enotkrutoy commited on
Commit
9d691cb
·
verified ·
1 Parent(s): 3844be7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -18
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 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
  ]
 
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
  ]