Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +38 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# Use environment variable for API key
|
8 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
9 |
+
|
10 |
+
# API endpoint and headers
|
11 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
12 |
+
headers = {
|
13 |
+
"Authorization": f"Bearer {groq_api_key}"
|
14 |
+
}
|
15 |
+
|
16 |
+
def chat_with_groq(user_input):
|
17 |
+
body = {
|
18 |
+
"model": "llama-3.1-8b-instant",
|
19 |
+
"messages": [
|
20 |
+
{"role": "user", "content": user_input}
|
21 |
+
]
|
22 |
+
}
|
23 |
+
response = requests.post(url, headers=headers, json=body)
|
24 |
+
if response.status_code == 200:
|
25 |
+
return response.json()['choices'][0]['message']['content']
|
26 |
+
else:
|
27 |
+
return f"Error: {response.json()}"
|
28 |
+
|
29 |
+
# Gradio interface
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=chat_with_groq,
|
32 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
|
33 |
+
outputs=gr.Textbox(),
|
34 |
+
title="DDS Chat with Groq AI (llama-3.1-8b-instant)",
|
35 |
+
description="Type your question below and get a response powered by Groq's llama model."
|
36 |
+
)
|
37 |
+
|
38 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
requests
|
3 |
+
groq
|