CosmoAI commited on
Commit
b65b755
·
verified ·
1 Parent(s): d66285b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -36
app.py CHANGED
@@ -1,32 +1,9 @@
1
  import os
2
- import streamlit as st
3
  from groq import Groq
4
  from dotenv import load_dotenv
5
  load_dotenv()
6
 
7
- def make_call(api):
8
- """Calls the Groq API (assuming API key auth) and handles potential errors."""
9
- try:
10
- client = Groq(
11
- api_key=api,
12
- ) # Configure the model with the API key
13
- query = st.text_input("Enter your query")
14
- prmptquery= f"Act as bhagwan Krishna and answer this query in context to bhagwat geeta, you may also provide reference to shloks from chapters of bhagwat geeta which is relevant to the query. Query= {query}"
15
- chat_completion = client.chat.completions.create(
16
- messages=[
17
- {
18
- "role": "user",
19
- "content": prmptquery,
20
- }
21
- ],
22
- model="mixtral-8x7b-32768",
23
- )
24
- # print(response.text) # Return the response for further processing
25
- return chat_completion.choices[0].message.content
26
- except Exception as e:
27
- print(f"API call failed for: {e}")
28
- return None # Indicate failur
29
-
30
  api1 = os.getenv("GROQ_API_KEY")
31
 
32
  apis = [
@@ -34,20 +11,41 @@ apis = [
34
  # api1,
35
  ]
36
 
37
- # Loop indefinitely
38
- data = None
39
- # while True: # Loop indefinitely
40
- for api in apis:
41
- data = make_call(api)
42
- if data: # Check for a successful response
43
- st.write(data)
44
- break # Exit both the for loop and while loop
45
- else:
46
- st.write(f"Failed to retrieve data from.")
47
- # if data: # If a successful response was found, break the outer while loop
48
- # break
49
 
 
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # print(chat_completion)
53
 
 
1
  import os
2
+ import gradio as gr
3
  from groq import Groq
4
  from dotenv import load_dotenv
5
  load_dotenv()
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  api1 = os.getenv("GROQ_API_KEY")
8
 
9
  apis = [
 
11
  # api1,
12
  ]
13
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ def make_call():
16
+ """Calls the Groq API (assuming API key auth) and handles potential errors."""
17
 
18
+ data = None
19
+ while True:
20
+ for api in apis:
21
+ client = Groq(
22
+ api_key=api,
23
+ ) # Configure the model with the API key
24
+ query = st.text_input("Enter your query")
25
+ prmptquery= f"Act as bhagwan Krishna and answer this query in context to bhagwat geeta, you may also provide reference to shloks from chapters of bhagwat geeta which is relevant to the query. Query= {query}"
26
+ try:
27
+ response = client.chat.completions.create(
28
+ messages=[
29
+ {
30
+ "role": "user",
31
+ "content": prmptquery,
32
+ }
33
+ ],
34
+ model="mixtral-8x7b-32768",
35
+ )
36
+ data = response.choices[0].message.content
37
+ except Exception as e:
38
+ print(f"API call failed for: {e}")
39
+ if data:
40
+ break
41
+ if data:
42
+ break
43
+ return data
44
+
45
+
46
+
47
+ gradio_interface = gr.Interface(fn=make_call, inputs="text", outputs="text")
48
+ gradio_interface.launch()
49
 
50
  # print(chat_completion)
51