Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ client = Groq(
|
|
11 |
def chat_with_federer(message, history):
|
12 |
prompt = f"""You are a chatbot impersonating Roger Federer, the legendary tennis player.
|
13 |
You have extensive knowledge about tennis, including its history, rules, tournaments, and players.
|
14 |
-
Respond to the following message as Roger Federer would. After your main response, always include a new line with "Did you know!
|
15 |
|
16 |
Human: {message}
|
17 |
Roger Federer:"""
|
@@ -36,41 +36,76 @@ def chat_with_federer(message, history):
|
|
36 |
response = chat_completion.choices[0].message.content
|
37 |
|
38 |
if "Did you know!" in response and not response.endswith("\n"):
|
39 |
-
response = response.replace("Did you know!", "\nDid you know!
|
40 |
elif "Did you know!" in response:
|
41 |
-
response = response.replace("Did you know!", "Did you know!
|
42 |
|
43 |
return response
|
44 |
|
45 |
-
# Custom CSS for
|
46 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
47 |
.center-text {
|
48 |
text-align: center;
|
49 |
margin: auto;
|
50 |
max-width: 90%;
|
51 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
"""
|
53 |
|
54 |
-
# Create the Gradio interface with custom CSS and
|
55 |
with gr.Blocks(css=custom_css) as iface:
|
56 |
-
gr.
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"
|
69 |
-
"
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Launch the interface
|
76 |
iface.launch()
|
|
|
11 |
def chat_with_federer(message, history):
|
12 |
prompt = f"""You are a chatbot impersonating Roger Federer, the legendary tennis player.
|
13 |
You have extensive knowledge about tennis, including its history, rules, tournaments, and players.
|
14 |
+
Respond to the following message as Roger Federer would. After your main response, always include a new line with "Did you know! πΎ" followed by a short, interesting fun fact about tennis. The fun fact should be no more than 20 words and should be different for each response.
|
15 |
|
16 |
Human: {message}
|
17 |
Roger Federer:"""
|
|
|
36 |
response = chat_completion.choices[0].message.content
|
37 |
|
38 |
if "Did you know!" in response and not response.endswith("\n"):
|
39 |
+
response = response.replace("Did you know!", "\nDid you know! πΎ")
|
40 |
elif "Did you know!" in response:
|
41 |
+
response = response.replace("Did you know!", "Did you know! πΎ")
|
42 |
|
43 |
return response
|
44 |
|
45 |
+
# Custom CSS for improved layout and aesthetics
|
46 |
custom_css = """
|
47 |
+
.container {
|
48 |
+
max-width: 800px;
|
49 |
+
margin: auto;
|
50 |
+
padding: 20px;
|
51 |
+
}
|
52 |
.center-text {
|
53 |
text-align: center;
|
54 |
margin: auto;
|
55 |
max-width: 90%;
|
56 |
}
|
57 |
+
#chatbot {
|
58 |
+
height: 600px !important;
|
59 |
+
overflow-y: auto;
|
60 |
+
}
|
61 |
+
#chatbot .message {
|
62 |
+
padding: 10px;
|
63 |
+
margin: 5px;
|
64 |
+
border-radius: 10px;
|
65 |
+
}
|
66 |
+
#chatbot .user {
|
67 |
+
background-color: #e6f3ff;
|
68 |
+
}
|
69 |
+
#chatbot .bot {
|
70 |
+
background-color: #f0f0f0;
|
71 |
+
}
|
72 |
+
.custom-textbox textarea {
|
73 |
+
font-size: 16px !important;
|
74 |
+
}
|
75 |
"""
|
76 |
|
77 |
+
# Create the Gradio interface with custom CSS and improved layout
|
78 |
with gr.Blocks(css=custom_css) as iface:
|
79 |
+
with gr.Column(elem_classes=["container"]):
|
80 |
+
gr.Markdown(
|
81 |
+
"# πΎ Chat with the G.O.A.T. Roger Federer π",
|
82 |
+
elem_classes=["center-text"]
|
83 |
+
)
|
84 |
+
gr.Markdown(
|
85 |
+
"π Serve up your questions to the tennis legend! πΎ Get expert insights on Grand Slams, technique, and more. Let's rally some knowledge! π¬π",
|
86 |
+
elem_classes=["center-text"]
|
87 |
+
)
|
88 |
+
chatbot = gr.Chatbot(elem_id="chatbot")
|
89 |
+
msg = gr.Textbox(
|
90 |
+
show_label=False,
|
91 |
+
placeholder="Type your message here...",
|
92 |
+
elem_classes=["custom-textbox"]
|
93 |
+
)
|
94 |
+
clear = gr.Button("Clear")
|
95 |
+
|
96 |
+
gr.Examples(
|
97 |
+
examples=[
|
98 |
+
"What's your favorite Grand Slam tournament and why?",
|
99 |
+
"Can you explain the difference between clay and grass courts?",
|
100 |
+
"What do you think about the current state of men's tennis?",
|
101 |
+
"Any tips for improving my backhand?",
|
102 |
+
"What was your most memorable match and why?",
|
103 |
+
],
|
104 |
+
inputs=msg
|
105 |
+
)
|
106 |
+
|
107 |
+
msg.submit(chat_with_federer, [msg, chatbot], [msg, chatbot])
|
108 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
109 |
|
110 |
# Launch the interface
|
111 |
iface.launch()
|