enotkrutoy commited on
Commit
d362e49
·
verified ·
1 Parent(s): 5221741

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -1,7 +1,7 @@
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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"
@@ -12,16 +12,25 @@ client = openai.OpenAI(
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.Textbox(placeholder="Ask something..."), # Updated component usage
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
  ]
 
1
  import os
2
  import openai
3
  import gradio as gr
4
+ import groq_gradio # Ensure this module exists and contains necessary functions
5
 
6
  # Set the environment variable for the Groq API key
7
  os.environ["GROQ_API_KEY"] = "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"
 
12
  api_key=os.environ.get("GROQ_API_KEY") # Use the environment variable to fetch the API key
13
  )
14
 
15
+ # Define the chat function
16
+ def chat_function(message):
17
+ # Call Groq API for completion based on the given message
18
+ response = client.chat_completions.create(
19
+ model="llama3-8b-8192",
20
+ messages=[{"role": "user", "content": message}]
21
+ )
22
+ return response.choices[0].message["content"]
23
+
24
  # Gradio interface setup
25
  gr.Interface(
26
+ fn=chat_function, # Function that handles the chatbot
27
+ inputs=gr.Textbox(placeholder="Ask something..."), # Input for user message
28
+ outputs="text", # Output as text
29
  title="Groq-Gradio Chat",
30
+ theme="upsatwal/mlsc_tiet", # Ensure theme is valid
31
  examples=[
32
  "Tell me a short story about a puppy",
33
+ "Write a 14-line poem about travelling in Shakespeare style",
34
  "What are the wonders of the world?",
35
  "List the countries in Africa and their capitals"
36
  ]