File size: 1,121 Bytes
dbd97c8
 
 
 
c82f10f
dbd97c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
import os
from groq import Groq

client = Groq(api_key=os.environ['GROQ_API_KEY'])


def get_response(question, model_choice):
    # Create a chat completion with the user's question and selected model
    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": f"you are created by Manish using Groq. {question}",
            }
        ],
        model=model_choice,
    )

    # Extract and return the response
    return chat_completion.choices[0].message.content

# Define the Gradio interface inputs including a Radio component for model selection
iface = gr.Interface(
    fn=get_response,
    inputs=[
        gr.Textbox(lines=2, placeholder="Enter your question here..."),
        gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768")
    ],
    outputs=gr.TextArea(label="Answer"),
    title="Groq Chat Assistant",
    description="Ask any question and select a model to get a response from the Groq chat model."
)

# Launch the app
iface.launch()