Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,38 @@
|
|
1 |
-
import os
|
2 |
-
import openai
|
3 |
import gradio as gr
|
|
|
|
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
)
|
10 |
|
11 |
-
# Define the
|
12 |
def chat_function(message):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Gradio interface setup
|
22 |
gr.Interface(
|
@@ -24,11 +40,11 @@ gr.Interface(
|
|
24 |
inputs=gr.Textbox(placeholder="Ask something..."), # Input for user message
|
25 |
outputs="text", # Output as text
|
26 |
title="Groq-Gradio Chat",
|
27 |
-
theme="
|
28 |
examples=[
|
29 |
"Tell me a short story about a puppy",
|
30 |
"Write a 14-line poem about travelling in Shakespeare style",
|
31 |
"What are the wonders of the world?",
|
32 |
"List the countries in Africa and their capitals"
|
33 |
]
|
34 |
-
).launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
|
5 |
+
# Set the API key
|
6 |
+
api_key = "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"
|
7 |
|
8 |
+
# Define the endpoint URL
|
9 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
|
|
10 |
|
11 |
+
# Define the request payload
|
12 |
def chat_function(message):
|
13 |
+
payload = {
|
14 |
+
"model": "lama3-8b-8192",
|
15 |
+
"messages": [
|
16 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
17 |
+
{"role": "user", "content": message}
|
18 |
+
],
|
19 |
+
"max_tokens": 150,
|
20 |
+
"temperature": 1,
|
21 |
+
"presence_penalty": 0,
|
22 |
+
"frequency_penalty": 0
|
23 |
+
}
|
24 |
+
|
25 |
+
headers = {
|
26 |
+
"Authorization": f"Bearer {api_key}",
|
27 |
+
"Content-Type": "application/json"
|
28 |
+
}
|
29 |
+
|
30 |
+
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
31 |
+
if response.status_code == 200:
|
32 |
+
data = response.json()
|
33 |
+
return data["choices"][0]["message"]["content"]
|
34 |
+
else:
|
35 |
+
return f"Error: {response.status_code}, {response.text}"
|
36 |
|
37 |
# Gradio interface setup
|
38 |
gr.Interface(
|
|
|
40 |
inputs=gr.Textbox(placeholder="Ask something..."), # Input for user message
|
41 |
outputs="text", # Output as text
|
42 |
title="Groq-Gradio Chat",
|
43 |
+
theme="gradio", # Use a valid theme
|
44 |
examples=[
|
45 |
"Tell me a short story about a puppy",
|
46 |
"Write a 14-line poem about travelling in Shakespeare style",
|
47 |
"What are the wonders of the world?",
|
48 |
"List the countries in Africa and their capitals"
|
49 |
]
|
50 |
+
).launch()
|