Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,27 @@
|
|
1 |
import os
|
2 |
-
import gradio as gr
|
3 |
import openai
|
|
|
4 |
import groq_gradio
|
5 |
|
6 |
-
# Set
|
7 |
os.environ["GROQ_API_KEY"] = "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"
|
8 |
|
9 |
-
# Initialize
|
10 |
client = openai.OpenAI(
|
11 |
base_url="https://api.groq.com/openai/v1",
|
12 |
-
api_key=os.environ.get("GROQ_API_KEY")
|
13 |
)
|
14 |
|
15 |
-
#
|
16 |
-
def generate_response(prompt):
|
17 |
-
response = openai.Completion.create(
|
18 |
-
model="llama-3.2-3b-preview",
|
19 |
-
prompt=prompt,
|
20 |
-
max_tokens=100
|
21 |
-
)
|
22 |
-
return response.choices[0].text.strip()
|
23 |
-
|
24 |
-
# Define the Gradio interface to use the Groq model through Gradio and Groq API
|
25 |
gr.Interface(
|
26 |
-
fn=
|
27 |
-
inputs=gr.Textbox(
|
28 |
-
outputs=
|
29 |
title="Groq-Gradio Chat",
|
30 |
theme="upsatwal/mlsc_tiet",
|
31 |
examples=[
|
32 |
"Tell me a short story about a puppy",
|
33 |
-
"Write a 14
|
34 |
"What are the wonders of the world?",
|
35 |
"List the countries in Africa and their capitals"
|
36 |
]
|
|
|
1 |
import os
|
|
|
2 |
import openai
|
3 |
+
import gradio as gr
|
4 |
import groq_gradio
|
5 |
|
6 |
+
# Set the environment variable for the Groq API key
|
7 |
os.environ["GROQ_API_KEY"] = "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"
|
8 |
|
9 |
+
# Initialize OpenAI client with Groq's API base URL
|
10 |
client = openai.OpenAI(
|
11 |
base_url="https://api.groq.com/openai/v1",
|
12 |
+
api_key=os.environ.get("GROQ_API_KEY") # Use the environment variable to fetch the API key
|
13 |
)
|
14 |
|
15 |
+
# Gradio interface setup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
gr.Interface(
|
17 |
+
fn=groq_gradio.registry, # Assuming the function used for the Groq model registry
|
18 |
+
inputs=gr.inputs.Textbox(placeholder="Ask something..."),
|
19 |
+
outputs="text",
|
20 |
title="Groq-Gradio Chat",
|
21 |
theme="upsatwal/mlsc_tiet",
|
22 |
examples=[
|
23 |
"Tell me a short story about a puppy",
|
24 |
+
"Write a 14 line poem about travelling in Shakespeare style",
|
25 |
"What are the wonders of the world?",
|
26 |
"List the countries in Africa and their capitals"
|
27 |
]
|