Poojashetty357 commited on
Commit
bc91bb6
·
verified ·
1 Parent(s): 9ec737e

Update app.py

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