decodingdatascience commited on
Commit
014bc9b
·
verified ·
1 Parent(s): 7a9a3b0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+
5
+ # Load Groq API key from environment variable
6
+ groq_api_key = os.getenv("GROQ_API_KEY")
7
+
8
+ # Groq API endpoint
9
+ url = "https://api.groq.com/openai/v1/chat/completions"
10
+
11
+ headers = {
12
+ "Authorization": f"Bearer {groq_api_key}"
13
+ }
14
+
15
+ # Function to call Groq API
16
+ def chat_with_groq(user_input):
17
+ body = {
18
+ "model": "llama-3.1-8b-instant",
19
+ "messages": [
20
+ {"role": "user", "content": user_input}
21
+ ]
22
+ }
23
+
24
+ response = requests.post(url, headers=headers, json=body)
25
+
26
+ if response.status_code == 200:
27
+ return response.json()['choices'][0]['message']['content']
28
+ else:
29
+ return f"Error: {response.json()}"
30
+
31
+ # Gradio interface
32
+ interface = gr.Interface(
33
+ fn=chat_with_groq,
34
+ inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
35
+ outputs=gr.Textbox(),
36
+ title="DDS Chat with Groq AI (Llama 3.1-8B)",
37
+ description="Ask your question to Groq's Llama 3.1-8B model."
38
+ )
39
+
40
+ interface.launch()