shivrajkarewar commited on
Commit
30c7434
·
verified ·
1 Parent(s): 0a525df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import os
4
+ import requests
5
+ import gradio as gr
6
+
7
+ from google.colab import userdata # Secure storage for API keys in Colab
8
+
9
+ groq_api_key = userdata.get("GROQ_API_KEY")
10
+
11
+ # Define the URL for the Groq API endpoint
12
+ url = "https://api.groq.com/openai/v1/chat/completions"
13
+
14
+ # Set the headers for the API request
15
+ headers = {
16
+ "Authorization": f"Bearer {groq_api_key}"
17
+ }
18
+
19
+ # Function to interact with Groq API
20
+ def chat_with_groq(user_input):
21
+ body = {
22
+ "model": "llama-3.3-70b-versatile",
23
+ "messages": [
24
+ {"role": "user", "content": user_input}
25
+ ]
26
+ }
27
+
28
+ response = requests.post(url, headers=headers, json=body)
29
+
30
+ if response.status_code == 200:
31
+ return response.json()['choices'][0]['message']['content']
32
+ else:
33
+ return f"Error: {response.json()}"
34
+
35
+ # Create Gradio interface
36
+ interface = gr.Interface(
37
+ fn=chat_with_groq,
38
+ inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
39
+ outputs=gr.Textbox(),
40
+ title="DDS Chat with Groq AI (Llama 3.1-8B)",
41
+ description="Type your question below and get a response powered by Groq's Llama 3.1-8B model."
42
+ )
43
+
44
+ # Launch Gradio app
45
+ interface.launch()