Spaces:
Sleeping
Sleeping
prithivMLmods
commited on
Commit
β’
23d9f29
1
Parent(s):
35da143
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import google.generativeai as genai
|
|
4 |
from dotenv import load_dotenv
|
5 |
import time
|
6 |
|
7 |
-
DESCRIPTIONx = """## GEMINI
|
8 |
"""
|
9 |
|
10 |
css = '''
|
@@ -50,7 +50,6 @@ mood_prompts = {
|
|
50 |
"Casual": "Respond in a relaxed and informal tone.",
|
51 |
"Formal": "Respond with a high level of formality.",
|
52 |
"Pessimistic": "Respond with a focus on potential negatives.",
|
53 |
-
"Optimistic": "Respond with a focus on potential positives.",
|
54 |
"Excited": "Respond with enthusiasm and excitement.",
|
55 |
"Melancholic": "Respond with a sense of sadness or longing.",
|
56 |
"Confident": "Respond with self-assurance and confidence.",
|
@@ -76,7 +75,6 @@ mood_prompts = {
|
|
76 |
"Hopeful": "Respond with a sense of hope and optimism.",
|
77 |
"Indifferent": "Respond with a lack of strong emotion.",
|
78 |
"Surprised": "Respond with shock and astonishment.",
|
79 |
-
"Sarcastic": "Respond with irony and wit.",
|
80 |
"Tense": "Respond with a sense of urgency or anxiety.",
|
81 |
"Enthusiastic": "Respond with eagerness and excitement.",
|
82 |
"Worried": "Respond with concern and apprehension."
|
@@ -93,22 +91,15 @@ def generate_response(user_input, chat_history, mood):
|
|
93 |
)
|
94 |
|
95 |
chat_history.append(user_input)
|
96 |
-
|
97 |
chat_history = chat_history[-10:]
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
except Exception as e:
|
107 |
-
if attempt < retry_attempts - 1:
|
108 |
-
time.sleep(2)
|
109 |
-
continue
|
110 |
-
else:
|
111 |
-
return f"Error after {retry_attempts} attempts: {str(e)}", chat_history
|
112 |
|
113 |
with gr.Blocks(css=css, theme="allenai/gradio-theme") as iface:
|
114 |
gr.Markdown(DESCRIPTIONx)
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
import time
|
6 |
|
7 |
+
DESCRIPTIONx = """## GEMINI::GEN β
|
8 |
"""
|
9 |
|
10 |
css = '''
|
|
|
50 |
"Casual": "Respond in a relaxed and informal tone.",
|
51 |
"Formal": "Respond with a high level of formality.",
|
52 |
"Pessimistic": "Respond with a focus on potential negatives.",
|
|
|
53 |
"Excited": "Respond with enthusiasm and excitement.",
|
54 |
"Melancholic": "Respond with a sense of sadness or longing.",
|
55 |
"Confident": "Respond with self-assurance and confidence.",
|
|
|
75 |
"Hopeful": "Respond with a sense of hope and optimism.",
|
76 |
"Indifferent": "Respond with a lack of strong emotion.",
|
77 |
"Surprised": "Respond with shock and astonishment.",
|
|
|
78 |
"Tense": "Respond with a sense of urgency or anxiety.",
|
79 |
"Enthusiastic": "Respond with eagerness and excitement.",
|
80 |
"Worried": "Respond with concern and apprehension."
|
|
|
91 |
)
|
92 |
|
93 |
chat_history.append(user_input)
|
|
|
94 |
chat_history = chat_history[-10:]
|
95 |
|
96 |
+
try:
|
97 |
+
chat_session = model.start_chat()
|
98 |
+
response = chat_session.send_message("\n".join(chat_history))
|
99 |
+
return response.text, chat_history
|
100 |
+
|
101 |
+
except Exception as e:
|
102 |
+
return f"Error: {str(e)}", chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
with gr.Blocks(css=css, theme="allenai/gradio-theme") as iface:
|
105 |
gr.Markdown(DESCRIPTIONx)
|