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,76 +36,41 @@ 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 |
-
.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
|
78 |
with gr.Blocks(css=custom_css) as iface:
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
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()
|
|
|
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, fun fact related to tennis. The fun fact should be no more than 15 words.
|
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 center alignment
|
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 updated title
|
55 |
with gr.Blocks(css=custom_css) as iface:
|
56 |
+
gr.Markdown(
|
57 |
+
"# πΎ Chat with the G.O.A.T. Roger Federer π",
|
58 |
+
elem_classes=["center-text"]
|
59 |
+
)
|
60 |
+
gr.Markdown(
|
61 |
+
"π Serve up your questions to the tennis legend! πΎ Get expert insights on Grand Slams, technique, and more. Let's rally some knowledge! π¬π",
|
62 |
+
elem_classes=["center-text"]
|
63 |
+
)
|
64 |
+
chatbot = gr.ChatInterface(
|
65 |
+
chat_with_federer,
|
66 |
+
examples=[
|
67 |
+
"What's your favorite Grand Slam tournament and why?",
|
68 |
+
"Can you explain the difference between clay and grass courts?",
|
69 |
+
"What do you think about the current state of men's tennis?",
|
70 |
+
"Any tips for improving my backhand?",
|
71 |
+
"What was your most memorable match and why?",
|
72 |
+
],
|
73 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Launch the interface
|
76 |
iface.launch()
|