Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import google.generativeai as genai
|
3 |
+
|
4 |
+
import os
|
5 |
+
token=os.environ.get("TOKEN")
|
6 |
+
genai.configure(api_key=token)
|
7 |
+
|
8 |
+
# Chargez l'image
|
9 |
+
model = genai.GenerativeModel(model_name="gemini-pro-vision")
|
10 |
+
model_simple = genai.GenerativeModel(model_name="gemini-pro")
|
11 |
+
|
12 |
+
e =""
|
13 |
+
# Fonction pour générer le contenu
|
14 |
+
def generate_content(image):
|
15 |
+
global e
|
16 |
+
|
17 |
+
if not image:
|
18 |
+
response = model_simple.generate_content(pro)
|
19 |
+
e = response.text
|
20 |
+
print(e)
|
21 |
+
|
22 |
+
else:
|
23 |
+
response = model.generate_content([pro, image])
|
24 |
+
print(response.text)
|
25 |
+
e = response.text
|
26 |
+
return e
|
27 |
+
|
28 |
+
|
29 |
+
markdown = r"""
|
30 |
+
e
|
31 |
+
""".format(e)
|
32 |
+
# Interface Gradio
|
33 |
+
iface = gr.Interface(fn=generate_content, inputs=gr.Image(type='pil'), outputs= gr.Markdown(markdown, latex_delimiters=[{ "left":"$$", "right":"$$", "display": True }]))
|
34 |
+
|
35 |
+
iface.launch()
|