Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Assuming `groq` is the correct package name and it has the described structure
|
| 5 |
+
from groq import Groq
|
| 6 |
+
|
| 7 |
+
client = Groq(api_key=userdata.get('GROQ_API_KEY'))
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_response(question, model_choice):
|
| 11 |
+
# Create a chat completion with the user's question and selected model
|
| 12 |
+
chat_completion = client.chat.completions.create(
|
| 13 |
+
messages=[
|
| 14 |
+
{
|
| 15 |
+
"role": "user",
|
| 16 |
+
"content": f"you are created by Manish using Groq. {question}",
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
model=model_choice,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Extract and return the response
|
| 23 |
+
return chat_completion.choices[0].message.content
|
| 24 |
+
|
| 25 |
+
# Define the Gradio interface inputs including a Radio component for model selection
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=get_response,
|
| 28 |
+
inputs=[
|
| 29 |
+
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 30 |
+
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768")
|
| 31 |
+
],
|
| 32 |
+
outputs=gr.TextArea(label="Answer"),
|
| 33 |
+
title="Groq Chat Assistant",
|
| 34 |
+
description="Ask any question and select a model to get a response from the Groq chat model."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Launch the app
|
| 38 |
+
iface.launch()
|