Kush1 commited on
Commit
421825f
1 Parent(s): 5ce8982

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
+ from dotenv import load_dotenv
5
+ import PIL.Image
6
+
7
+ load_dotenv()
8
+
9
+ genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
10
+
11
+ model = genai.GenerativeModel("gemini-pro-vision")
12
+
13
+
14
+
15
+ def process_image(img_path, prompt):
16
+ # Use the img_path directly to pass it to the model
17
+ print("Image Path:", img_path)
18
+ print("Prompt:", prompt)
19
+
20
+ img = PIL.Image.open(img_path)
21
+ response = model.generate_content([prompt, img], stream=True)
22
+ response.resolve()
23
+ return response.text
24
+
25
+ iface = gr.Interface(
26
+ fn=process_image,
27
+ inputs=[gr.Image(type="filepath"), gr.Textbox()],
28
+ outputs="text",
29
+ live=False,
30
+ )
31
+
32
+
33
+ iface.launch(share=True)