adhiltortil commited on
Commit
d9e781f
·
1 Parent(s): fc0d3ec

added app files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +77 -0
  3. requirements.txt +3 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GEMINI_API_KEY="AIzaSyDdSxbesv1iV3U-6I9w4l0eE1XPEItPhcA"
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from google import genai
3
+ from PIL import Image
4
+ import gradio as gr
5
+ from dotenv import load_dotenv
6
+
7
+ # Load environment variables
8
+ load_dotenv()
9
+
10
+
11
+
12
+ def analyze_images(image1, image2):
13
+ client = genai.Client(
14
+ api_key=os.getenv('GEMINI_API_KEY')
15
+ )
16
+
17
+ chat = client.chats.create(model="gemini-2.0-flash")
18
+
19
+ try:
20
+ img1 = Image.fromarray(image1)
21
+ img2 = Image.fromarray(image2)
22
+ response = chat.send_message([
23
+ img1,
24
+ img2,
25
+ "Spot the difference between 2 given images. The angles of the images will be different. Your task is to spot the missing or misplaced items"
26
+ ])
27
+ return response.text
28
+ except Exception as e:
29
+ return f"Error: {str(e)}"
30
+ def clear_inputs():
31
+ return None, None, "" # Returns None for both images and empty string for output
32
+
33
+
34
+
35
+ with gr.Blocks(theme=('hmb/amethyst')) as demo:
36
+ gr.Markdown("## Scene Continuity Checker")
37
+
38
+ # Image inputs in a row
39
+ with gr.Row():
40
+ image1_input = gr.Image(
41
+ label="First Image",
42
+ height=150,
43
+ width=150,
44
+ type="numpy"
45
+ )
46
+ image2_input = gr.Image(
47
+ label="Second Image",
48
+ height=150,
49
+ width=150,
50
+ type="numpy"
51
+ )
52
+
53
+ # Analysis output
54
+ output_text = gr.Textbox(
55
+ label="Analysis Results",
56
+ lines=4,
57
+ scale=2
58
+ )
59
+
60
+ # Buttons stacked vertically (removed gr.Row())
61
+ analyze_button = gr.Button("Analyze Differences", variant="primary")
62
+ clear_button = gr.Button("Reset", variant="secondary")
63
+
64
+ # Button click events
65
+ analyze_button.click(
66
+ fn=analyze_images,
67
+ inputs=[image1_input, image2_input],
68
+ outputs=output_text
69
+ )
70
+
71
+ clear_button.click(
72
+ fn=clear_inputs,
73
+ inputs=[],
74
+ outputs=[image1_input, image2_input, output_text]
75
+ )
76
+
77
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-genai
2
+ pillow
3
+ python-dotenv