Ankit18006 commited on
Commit
7112f7f
1 Parent(s): 42637e6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import PIL.Image
4
+
5
+ # Configure the API key directly
6
+ api_key = "AIzaSyA5xydka73TOQ9CQQnc3x0Fez5ZGqkFtqY"
7
+ genai.configure(api_key=api_key)
8
+
9
+ # Initialize the generative model
10
+ model = genai.GenerativeModel("gemini-1.5-flash")
11
+
12
+ def process_image(img_path, prompt):
13
+ print("Image Path:", img_path)
14
+ print("Prompt:", prompt)
15
+
16
+ # Open the image
17
+ img = PIL.Image.open(img_path)
18
+
19
+ # Generate content based on the image and prompt
20
+ response = model.generate_content([prompt, img], stream=True)
21
+ response.resolve()
22
+
23
+ return response.text
24
+
25
+ # Set up the Gradio interface
26
+ iface = gr.Interface(
27
+ fn=process_image,
28
+ inputs=[gr.Image(type="filepath"), gr.Textbox()],
29
+ outputs="text",
30
+ live=False,
31
+ )
32
+
33
+ # Launch the interface with sharing enabled
34
+ iface.launch(share=True)