Update app.py
Browse files
app.py
CHANGED
@@ -19,18 +19,18 @@ print("google-generativeai:", genai.__version__)
|
|
19 |
|
20 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
21 |
|
22 |
-
TITLE = """<h1 align="center"
|
23 |
-
SUBTITLE = """<h2 align="center">Play with Gemini Pro and Gemini Pro Vision API 🖇️</h2>"""
|
24 |
-
DUPLICATE = """
|
25 |
-
<div style="text-align: center; display: flex; justify-content: center; align-items: center;">
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
</div>
|
33 |
-
"""
|
34 |
|
35 |
|
36 |
IMAGE_WIDTH = 512
|
@@ -112,10 +112,10 @@ def bot(
|
|
112 |
|
113 |
#text_prompt = chatbot[-1][0]
|
114 |
txt_in = chatbot[-1][0]
|
115 |
-
if "youtube" in txt_in:
|
116 |
-
|
117 |
-
else:
|
118 |
-
|
119 |
|
120 |
genai.configure(api_key=google_key)
|
121 |
|
@@ -125,8 +125,9 @@ def bot(
|
|
125 |
stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
|
126 |
top_k=40,
|
127 |
top_p=0.95)
|
128 |
-
|
129 |
-
if
|
|
|
130 |
prompt= "استخرج كلمات مفتاحية من النص التالي: "+text_prompt
|
131 |
model = genai.GenerativeModel('gemini-pro')
|
132 |
response = model.generate_content(
|
@@ -146,6 +147,16 @@ def bot(
|
|
146 |
generation_config=generation_config, safety_settings=safety_settings)
|
147 |
response2.resolve()
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
else:
|
150 |
prompt= "اكتب لي وصف عن الصورة المرفقة "
|
151 |
image_prompt = preprocess_image(image_prompt)
|
@@ -208,8 +219,10 @@ chatbot_component = gr.Chatbot(
|
|
208 |
rtl=True
|
209 |
)
|
210 |
text_prompt_component = gr.Textbox(
|
211 |
-
placeholder="
|
212 |
-
label="
|
|
|
|
|
213 |
)
|
214 |
run_button_component = gr.Button()
|
215 |
temperature_component = gr.Slider(
|
@@ -297,13 +310,13 @@ with gr.Blocks() as demo:
|
|
297 |
chatbot_component.render()
|
298 |
text_prompt_component.render()
|
299 |
run_button_component.render()
|
300 |
-
with gr.Accordion("Parameters", open=False):
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
|
308 |
run_button_component.click(
|
309 |
fn=user,
|
|
|
19 |
|
20 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
21 |
|
22 |
+
TITLE = """<h1 align="center">تجربة جزئية إقتراح الآيات من ضياء</h1>"""
|
23 |
+
# SUBTITLE = """<h2 align="center">Play with Gemini Pro and Gemini Pro Vision API 🖇️</h2>"""
|
24 |
+
# DUPLICATE = """
|
25 |
+
# <div style="text-align: center; display: flex; justify-content: center; align-items: center;">
|
26 |
+
# <a href="https://huggingface.co/spaces/SkalskiP/ChatGemini?duplicate=true">
|
27 |
+
# <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space" style="margin-right: 10px;">
|
28 |
+
# </a>
|
29 |
+
# <span>Duplicate the Space and run securely with your
|
30 |
+
# <a href="https://makersuite.google.com/app/apikey">GOOGLE API KEY</a>.
|
31 |
+
# </span>
|
32 |
+
# </div>
|
33 |
+
# """
|
34 |
|
35 |
|
36 |
IMAGE_WIDTH = 512
|
|
|
112 |
|
113 |
#text_prompt = chatbot[-1][0]
|
114 |
txt_in = chatbot[-1][0]
|
115 |
+
# if "youtube" in txt_in:
|
116 |
+
# text_prompt = extract_text_from(txt_in)
|
117 |
+
# else:
|
118 |
+
# text_prompt = txt_in
|
119 |
|
120 |
genai.configure(api_key=google_key)
|
121 |
|
|
|
125 |
stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
|
126 |
top_k=40,
|
127 |
top_p=0.95)
|
128 |
+
|
129 |
+
if "youtube" in txt_in:
|
130 |
+
text_prompt = extract_text_from(txt_in)
|
131 |
prompt= "استخرج كلمات مفتاحية من النص التالي: "+text_prompt
|
132 |
model = genai.GenerativeModel('gemini-pro')
|
133 |
response = model.generate_content(
|
|
|
147 |
generation_config=generation_config, safety_settings=safety_settings)
|
148 |
response2.resolve()
|
149 |
|
150 |
+
elif image_prompt is None:
|
151 |
+
model2 = genai.GenerativeModel('gemini-pro')
|
152 |
+
|
153 |
+
prompt = "أذكر لي آية من القران الكريم تتحدث عن أحد هذه المواضيع او اكثر: "+ txt_in + " واشرح الآيه وفسرها باللغة العربية."
|
154 |
+
response2 = model2.generate_content(
|
155 |
+
prompt,
|
156 |
+
stream=True,
|
157 |
+
generation_config=generation_config, safety_settings=safety_settings)
|
158 |
+
response2.resolve()
|
159 |
+
|
160 |
else:
|
161 |
prompt= "اكتب لي وصف عن الصورة المرفقة "
|
162 |
image_prompt = preprocess_image(image_prompt)
|
|
|
219 |
rtl=True
|
220 |
)
|
221 |
text_prompt_component = gr.Textbox(
|
222 |
+
placeholder="مرحبا!",
|
223 |
+
label="ادخل رابط يوتيوب لإستخراج الآيات أو نص\موضوع معين",
|
224 |
+
rtl = True
|
225 |
+
|
226 |
)
|
227 |
run_button_component = gr.Button()
|
228 |
temperature_component = gr.Slider(
|
|
|
310 |
chatbot_component.render()
|
311 |
text_prompt_component.render()
|
312 |
run_button_component.render()
|
313 |
+
# with gr.Accordion("Parameters", open=False):
|
314 |
+
# temperature_component.render()
|
315 |
+
# max_output_tokens_component.render()
|
316 |
+
# stop_sequences_component.render()
|
317 |
+
# with gr.Accordion("Advanced", open=False):
|
318 |
+
# top_k_component.render()
|
319 |
+
# top_p_component.render()
|
320 |
|
321 |
run_button_component.click(
|
322 |
fn=user,
|