Spaces:
Running
Running
Upload 2 files
Browse files- app.py +40 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import google.generativeai as genai
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
def generate_content(api_key, prompt, image_data):
|
8 |
+
|
9 |
+
genai.configure(api_key=api_key)
|
10 |
+
|
11 |
+
# Convert uploaded binary data into a PIL image.
|
12 |
+
# image = Image.open(io.BytesIO(image_data))
|
13 |
+
image = Image.fromarray(np.uint8(image_data)).convert('RGB')
|
14 |
+
|
15 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
16 |
+
|
17 |
+
response = model.generate_content([prompt, image])
|
18 |
+
response.resolve()
|
19 |
+
return response.text
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
with gr.Blocks() as app:
|
24 |
+
gr.Markdown("# Morshen micro is demo")
|
25 |
+
gr.Markdown("https://ai.google.dev/")
|
26 |
+
api_key_input = gr.Textbox(label="API Key", type="password", value="AIzaSyBx6NCOCoNTpvock5As8_IYctd_zGqom4U", placeholder="Enter your API Key", lines=1)
|
27 |
+
|
28 |
+
# image_input = gr.File(label="Upload an image", type="binary")
|
29 |
+
image_input = gr.Image(label="Загрузить изображение ")
|
30 |
+
prompt_input = gr.Textbox(label="Функция", placeholder="Enter your Prompt", value="Идентификация вируса/бактерии и назначение по лечению ",lines=3)
|
31 |
+
generate_button = gr.Button("Пуск")
|
32 |
+
output = gr.Markdown()
|
33 |
+
|
34 |
+
generate_button.click(
|
35 |
+
generate_content,
|
36 |
+
inputs=[api_key_input, prompt_input, image_input],
|
37 |
+
outputs=output
|
38 |
+
)
|
39 |
+
|
40 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
google-generativeai==0.3.1
|
2 |
+
gradio
|