reshav1 commited on
Commit
5a97319
1 Parent(s): 91fe5c5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -0
app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import streamlit as st
4
+
5
+ from groq import Groq
6
+
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+
12
+
13
+
14
+ def make_call(api):
15
+
16
+ """Calls the Groq API (assuming API key auth) and handles potential errors."""
17
+
18
+ try:
19
+
20
+ client = Groq(
21
+
22
+ api_key=api,
23
+
24
+ ) # Configure the model with the API key
25
+
26
+ query = st.text_input("Enter your query")
27
+
28
+ prmptquery= f"give the answer of given query in context to bhagwat geeta: {query}"
29
+
30
+ chat_completion = client.chat.completions.create(
31
+
32
+ messages=[
33
+
34
+ {
35
+
36
+ "role": "user",
37
+
38
+ "content": prmptquery,
39
+
40
+ }
41
+
42
+ ],
43
+
44
+ model="mixtral-8x7b-32768",
45
+
46
+ )
47
+
48
+ # print(response.text) # Return the response for further processing
49
+
50
+ return chat_completion.choices[0].message.content
51
+
52
+ except Exception as e:
53
+
54
+ print(f"API call failed for: {e}")
55
+
56
+ return None # Indicate failur
57
+
58
+
59
+
60
+
61
+ api1 = os.getenv("GROQ_API_KEY")
62
+
63
+
64
+
65
+
66
+ apis = [
67
+
68
+ api1,
69
+
70
+ # api1,
71
+
72
+ ]
73
+
74
+
75
+
76
+
77
+ # Loop indefinitely
78
+
79
+ data = None
80
+
81
+ # while True: # Loop indefinitely
82
+
83
+ for api in apis:
84
+
85
+ data = make_call(api)
86
+
87
+ if data: # Check for a successful response
88
+
89
+ st.write(data)
90
+
91
+ break # Exit both the for loop and while loop
92
+
93
+ else:
94
+
95
+ st.write(f"Failed to retrieve data from.")
96
+
97
+ # if data: # If a successful response was found, break the outer while loop
98
+
99
+ # break