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