Spaces:
Runtime error
Runtime error
File size: 1,389 Bytes
0017a07 d8da427 0017a07 a1a1c08 0017a07 d8da427 0017a07 3844be7 d362e49 0017a07 7826328 0017a07 d8da427 a1a1c08 d8da427 7826328 0017a07 d8da427 0017a07 d8da427 0017a07 |
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 37 38 39 40 |
import gradio as gr
import openai
import os
# Set the base URL for the Groq API
openai.api_base = "https://api.groq.com/openai/v1"
openai.api_key = os.getenv("GROQ_API_KEY") # Fetch API key from environment variable
def chat_function(message):
# Define the request payload
payload = {
"model": "mixtral-8x7b-32768", # Specify your model here (e.g., Groq's supported model)
"messages": [{"role": "user", "content": message}],
"max_tokens": 150,
"temperature": 1
}
try:
# Send the request to the Groq API and get the response
response = openai.ChatCompletion.create(**payload)
return response["choices"][0]["message"]["content"]
except Exception as e:
return f"Error: {str(e)}"
# Set up the Gradio interface
gr.Interface(
fn=chat_function, # The function that handles user input
inputs=gr.Textbox(placeholder="Ask something..."), # User input text box
outputs="text", # Output text box for the response
title="Groq-Gradio Chat", # Interface title
theme="huggingface", # Use a valid Gradio theme
examples=[
"Tell me a short story about a puppy",
"Write a 14-line poem about travelling in Shakespeare style",
"What are the wonders of the world?",
"List the countries in Africa and their capitals"
] # Example prompts
).launch()
|