CosmoAI commited on
Commit
58e10d4
·
verified ·
1 Parent(s): dca59c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -18,28 +18,36 @@ def make_call(data):
18
  language = items['lang']
19
  query = items['text']
20
  query = query.lower()
21
- answer = None
22
 
23
  # Use the GenerativeModel class to interact with Gemini
24
  model = genai.GenerativeModel('gemini-pro') # You can choose a different Gemini model
25
 
26
- while True:
27
- try:
28
- # Craft your prompt specific for Gemini and desired output format
29
- prompt_query = f"Answer this query in a short message with wisdom, love, and compassion, in context to Bhagavad Gita, that feels like chatting to a person and provide references of shlokas from chapters of Bhagavad Gita which are relevant to the query. Keep the answer short, precise, and simple. Query: {query}"
30
-
31
- # Generate content using Gemini
32
- response = model.generate_content(prompt_query)
33
-
34
- # Access the generated text from the response
35
- answer = response.text # The generated content is in the 'text' attribute
36
-
37
- # Translate the answer
38
- translated = GoogleTranslator(source='auto', target=language).translate(answer)
39
- except Exception as e:
40
- print(f"API call failed for: {e}")
41
- if answer:
42
- break
 
 
 
 
 
 
 
 
43
 
44
  respo = {
45
  "message": translated,
@@ -54,6 +62,7 @@ gradio_interface.launch()
54
 
55
 
56
 
 
57
  # import os
58
  # import gradio as gr
59
  # from groq import Groq
 
18
  language = items['lang']
19
  query = items['text']
20
  query = query.lower()
21
+ translated = None # Initialize translated to None, it will hold the final output message
22
 
23
  # Use the GenerativeModel class to interact with Gemini
24
  model = genai.GenerativeModel('gemini-pro') # You can choose a different Gemini model
25
 
26
+ try:
27
+ # Craft your prompt specific for Gemini and desired output format
28
+ prompt_query = (
29
+ f"Answer this query in a short message with wisdom, love, and compassion, "
30
+ f"in context to Bhagavad Gita, that feels like chatting to a person and "
31
+ f"provide references of shlokas from chapters of Bhagavad Gita which are "
32
+ f"relevant to the query. Keep the answer short, precise, and simple. "
33
+ f"Query: {query}"
34
+ )
35
+
36
+ # Generate content using Gemini
37
+ response = model.generate_content(prompt_query)
38
+
39
+ # Access the generated text from the response
40
+ answer = response.text # The generated content is in the 'text' attribute
41
+
42
+ # Translate the answer
43
+ translated = GoogleTranslator(source='auto', target=language).translate(answer)
44
+ except Exception as e:
45
+ print(f"API call failed for: {e}")
46
+ # Provide an informative message to the user in case of an error
47
+ translated = f"An error occurred while fetching the answer: {e}"
48
+ # Optionally, you might want to log the full traceback for debugging:
49
+ # import traceback
50
+ # traceback.print_exc()
51
 
52
  respo = {
53
  "message": translated,
 
62
 
63
 
64
 
65
+
66
  # import os
67
  # import gradio as gr
68
  # from groq import Groq