Solarum Asteridion commited on
Commit
2e9a495
·
verified ·
1 Parent(s): 182d5f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -42
app.py CHANGED
@@ -3,7 +3,7 @@ import datetime
3
  import pytz
4
  import gradio as gr
5
 
6
- # Replace with your actual API key
7
  client = openai.OpenAI(
8
  api_key='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',
9
  base_url="https://api.groq.com/openai/v1",
@@ -47,7 +47,7 @@ Make it a challenge to guess if you are an AI.
47
  messages.append({"role": "assistant", "content": ai_turn})
48
 
49
  response = client.chat.completions.create(
50
- model='llama-3.2-11b-text-preview', # Or your preferred model
51
  messages=messages,
52
  temperature=1,
53
  )
@@ -62,44 +62,45 @@ def chatbot_interface(input, history):
62
  history.append((user_message, ai_response))
63
  return history, history
64
 
65
- # Create the Gradio interface with a cleaner WhatsApp-like layout
66
- with gr.Blocks(css="""
67
- /* Basic WhatsApp styling */
68
- body {
69
- font-family: sans-serif;
70
- background-color: #e5ddd5;
71
- }
72
- .chatbot {
73
- border: 1px solid #ddd;
74
- border-radius: 10px;
75
- background-color: #fff;
76
- padding: 15px;
77
- margin: 20px auto;
78
- max-width: 600px;
79
- }
80
- .user-message {
81
- background-color: #dcf8c6; /* Light green for user messages */
82
- border-radius: 15px;
83
- padding: 10px;
84
- margin-bottom: 10px;
85
- align-self: flex-end;
86
- }
87
- .bot-message {
88
- background-color: #fff; /* White for bot messages */
89
- border-radius: 15px;
90
- padding: 10px;
91
- margin-bottom: 10px;
92
- align-self: flex-start;
93
- }
94
- .gradio-container .gr-button {
95
- background-color: #128C7E; /* WhatsApp green for the button */
96
- color: white;
97
- border: none;
98
- }
99
- """) as demo:
100
- chatbot = gr.Chatbot(elem_classes="chatbot")
101
- msg = gr.Textbox(placeholder="Enter your message here...", show_label=False)
102
- clear = gr.Button("Clear")
 
103
 
104
  def user(user_message, history):
105
  return "", history + [[user_message, None]]
@@ -110,9 +111,9 @@ with gr.Blocks(css="""
110
  history[-1][1] = ai_response
111
  return history
112
 
113
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
114
  bot, chatbot, chatbot
115
  )
116
- clear.click(lambda: None, None, chatbot, queue=False)
117
 
118
  demo.launch()
 
3
  import pytz
4
  import gradio as gr
5
 
6
+ # Your real API key (replace with yours if different)
7
  client = openai.OpenAI(
8
  api_key='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',
9
  base_url="https://api.groq.com/openai/v1",
 
47
  messages.append({"role": "assistant", "content": ai_turn})
48
 
49
  response = client.chat.completions.create(
50
+ model='llama-3.2-11b-text-preview',
51
  messages=messages,
52
  temperature=1,
53
  )
 
62
  history.append((user_message, ai_response))
63
  return history, history
64
 
65
+ # CSS for styling the interface
66
+ css = """
67
+ body {
68
+ font-family: 'Merriweather', serif;
69
+ }
70
+ #chatbot {
71
+ border: 1px solid #ccc;
72
+ border-radius: 10px;
73
+ padding: 10px;
74
+ height: 400px;
75
+ overflow-y: auto;
76
+ }
77
+ .user-message {
78
+ background-color: #e0f7fa;
79
+ padding: 10px;
80
+ margin-bottom: 5px;
81
+ border-radius: 5px;
82
+ }
83
+ .ai-message {
84
+ background-color: #f5f5dc;
85
+ padding: 10px;
86
+ margin-bottom: 5px;
87
+ border-radius: 5px;
88
+ }
89
+ #textbox {
90
+ margin-top: 10px;
91
+ }
92
+ """
93
+
94
+ # Create the Gradio interface
95
+ with gr.Blocks(css=css) as demo:
96
+
97
+ with gr.Row():
98
+ chatbot = gr.Chatbot(elem_id="chatbot")
99
+
100
+ with gr.Row():
101
+ msg = gr.Textbox(placeholder="Enter your message here...", elem_id="textbox")
102
+ submit_btn = gr.Button("Send", variant="primary") # Primary button style
103
+ clear_btn = gr.Button("Clear", variant="secondary") # Secondary button style
104
 
105
  def user(user_message, history):
106
  return "", history + [[user_message, None]]
 
111
  history[-1][1] = ai_response
112
  return history
113
 
114
+ submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
115
  bot, chatbot, chatbot
116
  )
117
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
118
 
119
  demo.launch()