CosmoAI commited on
Commit
b3630c7
1 Parent(s): 9bfebe1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  from groq import Groq
4
  from dotenv import load_dotenv
5
  import json
 
6
  load_dotenv()
7
 
8
  api1 = os.getenv("GROQ_API_KEY")
@@ -15,6 +16,9 @@ apis = [
15
 
16
  def make_call(data):
17
  print(data)
 
 
 
18
  answer = None
19
  while True:
20
  for api in apis:
@@ -22,7 +26,7 @@ def make_call(data):
22
  api_key=api,
23
  ) # Configure the model with the API key
24
  # query = st.text_input("Enter your query")
25
- prmptquery= f"Answer this query as a friend with wisdom, love and compassion, in context to bhagwat geeta, provide references of shloks from chapters of bhagwat geeta which is relevant to the query. Query= {data}"
26
  try:
27
  response = client.chat.completions.create(
28
  messages=[
@@ -34,6 +38,7 @@ def make_call(data):
34
  model="mixtral-8x7b-32768",
35
  )
36
  answer = response.choices[0].message.content
 
37
  except Exception as e:
38
  print(f"API call failed for: {e}")
39
  if answer:
@@ -41,7 +46,7 @@ def make_call(data):
41
  if answer:
42
  break
43
  respo = {
44
- "message": answer,
45
  "action": "nothing",
46
  "function": "nothing",
47
  }
 
3
  from groq import Groq
4
  from dotenv import load_dotenv
5
  import json
6
+ from deep_translator import GoogleTranslator
7
  load_dotenv()
8
 
9
  api1 = os.getenv("GROQ_API_KEY")
 
16
 
17
  def make_call(data):
18
  print(data)
19
+ items = json.loads(data)
20
+ language = items['lang']
21
+ query = items['text']
22
  answer = None
23
  while True:
24
  for api in apis:
 
26
  api_key=api,
27
  ) # Configure the model with the API key
28
  # query = st.text_input("Enter your query")
29
+ prmptquery= f"Answer this query with wisdom, love and compassion, in context to bhagwat geeta, provide references of shloks from chapters of bhagwat geeta which is relevant to the query. Query= {query}"
30
  try:
31
  response = client.chat.completions.create(
32
  messages=[
 
38
  model="mixtral-8x7b-32768",
39
  )
40
  answer = response.choices[0].message.content
41
+ translated = GoogleTranslator(source='auto', target=language).translate(answer)
42
  except Exception as e:
43
  print(f"API call failed for: {e}")
44
  if answer:
 
46
  if answer:
47
  break
48
  respo = {
49
+ "message": translated,
50
  "action": "nothing",
51
  "function": "nothing",
52
  }