Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cohere
|
| 3 |
+
|
| 4 |
+
API_KEY = "MIruAnyAZJg3bkwNyKf8xadKzzX1yIxbkHbap4PP"
|
| 5 |
+
co = cohere.ClientV2(api_key=API_KEY)
|
| 6 |
+
|
| 7 |
+
def chatbot(user_message, history):
|
| 8 |
+
# Send only the latest user message to Cohere
|
| 9 |
+
cohere_messages = [{
|
| 10 |
+
"role": "user",
|
| 11 |
+
"content": [{"type": "text", "text": user_message}]
|
| 12 |
+
}]
|
| 13 |
+
|
| 14 |
+
response = co.chat(
|
| 15 |
+
messages=cohere_messages,
|
| 16 |
+
temperature=0.3,
|
| 17 |
+
model="command-a-03-2025",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
assistant_reply = response.message.content[0].text
|
| 21 |
+
|
| 22 |
+
# Instead of appending, overwrite history with just this turn
|
| 23 |
+
return [
|
| 24 |
+
{"role": "user", "content": user_message},
|
| 25 |
+
{"role": "assistant", "content": assistant_reply},
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## 🤖 SIRMVIT CSE Chatbot ")
|
| 30 |
+
gr.ChatInterface(fn=chatbot, type="messages")
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|
requirements.txt
ADDED
|
Binary file (30 Bytes). View file
|
|
|