Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,28 +18,36 @@ def make_call(data):
|
|
| 18 |
language = items['lang']
|
| 19 |
query = items['text']
|
| 20 |
query = query.lower()
|
| 21 |
-
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|