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()