Spaces:
Sleeping
Sleeping
Solarum Asteridion
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import datetime
|
|
| 3 |
import pytz
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
#
|
| 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',
|
| 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 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
| 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 |
-
|
| 114 |
bot, chatbot, chatbot
|
| 115 |
)
|
| 116 |
-
|
| 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()
|