siddhartharya commited on
Commit
b7359cb
Β·
verified Β·
1 Parent(s): ea2795c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -58
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! 🎾" 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,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 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()
 
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()