Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,37 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import groq_gradio
|
3 |
-
import os
|
4 |
|
|
|
5 |
os.environ["GROQ_API_KEY"] = "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"
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
import openai
|
4 |
import groq_gradio
|
|
|
5 |
|
6 |
+
# Set up the API key
|
7 |
os.environ["GROQ_API_KEY"] = "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"
|
8 |
+
|
9 |
+
# Initialize the OpenAI client to use the Groq API endpoint
|
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 |
+
# Define a function to generate a response using Groq API
|
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=generate_response,
|
27 |
+
inputs=gr.Textbox(label="Enter your prompt here:"),
|
28 |
+
outputs=gr.Textbox(label="Response from Groq model:"),
|
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-line poem about traveling in Shakespeare style",
|
34 |
+
"What are the wonders of the world?",
|
35 |
+
"List the countries in Africa and their capitals"
|
36 |
+
]
|
37 |
+
).launch()
|