Spaces:
Build error
Build error
Update app.py
Browse files1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839401 unmodified lineimport requestsimport gradio as gr# Load Groq API key from environment variablegroq_api_key = os.getenv("GROQ_API_KEY")# Groq API endpointurl = "https://api.groq.com/openai/v1/chat/completions"headers = {"Authorization": f"Bearer {groq_api_key}"}# Function to call Groq APIdef chat_with_groq(user_input):body = {"model": "llama-3.1-8b-instant","messages": [{"role": "user", "content": user_input}]}response = requests.post(url, headers=headers, json=body)if response.status_code == 200:return response.json()['choices'][0]['message']['content']else:return f"Error: {response.json()}"# Gradio interfaceinterface = gr.Interface(fn=chat_with_groq,inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),outputs=gr.Textbox(),title="DDS Chat with Groq AI (Llama 3.1-8B)",description="Ask your question to Groq's Llama 3.1-8B model.")interface.launch()1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051521 unmodified lineimport requestsimport gradio as gr# Get Groq API key from environment variablegroq_api_key = os.environ.get("GROQ_API_KEY")if not groq_api_key:raise ValueError("Please set the GROQ_API_KEY in the Hugging Face Space secrets.")# Groq API configurationurl = "https://api.groq.com/openai/v1/chat/completions"headers = {"Authorization": f"Bearer {groq_api_key}"}# Prompt templatetemplate = """You are a friendly and professional customer service assistant for a telecom company.Respond to the customer's issue below with empathy and clear steps, especially for roaming support.Customer Query: {query}Your Response:"""# Function to call Groq APIdef generate_response(user_query):structured_prompt = template.format(query=user_query)body = {"model": "llama-3.1-8b-instant","messages": [{"role": "user","content": structured_prompt}]}response = requests.post(url, headers=headers, json=body)if response.status_code == 200:return response.json()['choices'][0]['message']['content']else:return f"Error {response.status_code}: {response.text}"# Gradio interfacegr.Interface(fn=generate_response,inputs=gr.Textbox(lines=4, placeholder="Describe your telecom issue..."),outputs=gr.Textbox(label="Groq API Response"),title="Telecom Support Assistant",description="Ask your question and get a helpful reply from our AI-powered support assistant.").launch()
app.py+29-17