Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
openai.api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
+
openai.api_base = "https://api.groq.com/openai/v1"
|
| 7 |
+
|
| 8 |
+
def get_groq_response(message):
|
| 9 |
+
try:
|
| 10 |
+
response = openai.ChatCompletion.create(
|
| 11 |
+
model = "llama-3.1-70b-versatile",
|
| 12 |
+
messages = [
|
| 13 |
+
{"role": "system", "content": "roast him/her to politely"},
|
| 14 |
+
{"role": "user", "content": message}
|
| 15 |
+
]
|
| 16 |
+
)
|
| 17 |
+
return response.choices[0].message["content"]
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {str(e)}"
|
| 20 |
+
|
| 21 |
+
def chatbot(Tere_Dil_ki_baat, history = []):
|
| 22 |
+
bot_response = get_groq_response(Tere_Dil_ki_baat)
|
| 23 |
+
history.append((Tere_Dil_ki_baat, bot_response))
|
| 24 |
+
return history, history
|
| 25 |
+
|
| 26 |
+
chat_interface = gr.Interface(
|
| 27 |
+
fn=chatbot,
|
| 28 |
+
inputs= ["text", "state"],
|
| 29 |
+
outputs=["chatbot", "state"],
|
| 30 |
+
live=False,
|
| 31 |
+
title="maan ki baat",
|
| 32 |
+
description="maan ki baat :"
|
| 33 |
+
)
|
| 34 |
+
chat_interface.launch()
|