Jeff28 commited on
Commit
294f796
·
verified ·
1 Parent(s): 4027cce

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Dummy model functions for each version
4
+ def model_v1(image):
5
+ # Process the image with Model Version 1
6
+ return "Model V1: Detected disease - [Example Disease]"
7
+
8
+ def model_v2(image):
9
+ # First validate image is a tomato leaf, then predict disease
10
+ return "Model V2: Detected disease after validation - [Example Disease]"
11
+
12
+ def model_v3(image):
13
+ # Use an alternative architecture for prediction
14
+ return "Model V3: Detected disease with advanced analysis - [Example Disease]"
15
+
16
+ # Main function to select the proper model based on the version choice
17
+ def process_image(image, version):
18
+ if image is None:
19
+ return "No image provided."
20
+ if version == "Version 1":
21
+ return model_v1(image)
22
+ elif version == "Version 2":
23
+ return model_v2(image)
24
+ elif version == "Version 3":
25
+ return model_v3(image)
26
+ else:
27
+ return "Invalid version selected."
28
+
29
+ # A helper to choose between uploaded image and camera image.
30
+ def combine_images(uploaded, camera):
31
+ # Prioritize the camera image if provided
32
+ return camera if camera is not None else uploaded
33
+
34
+ # Define the Gradio Blocks interface
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# FarmVi8ion – AI-powered Crop Monitoring")
37
+ gr.Markdown("An advanced system for detecting tomato diseases using AI models.")
38
+
39
+ with gr.Row():
40
+ # Sidebar column: version and theme selection
41
+ with gr.Column(scale=1):
42
+ version = gr.Radio(
43
+ ["Version 1", "Version 2", "Version 3"],
44
+ label="Select Model Version",
45
+ value="Version 1"
46
+ )
47
+ theme_choice = gr.Radio(
48
+ ["Light", "Dark"],
49
+ label="Select Theme",
50
+ value="Light"
51
+ )
52
+ gr.Markdown("Upload an image or use the camera preview below.")
53
+
54
+ # Main column: image inputs and results
55
+ with gr.Column(scale=2):
56
+ # Image input for file upload
57
+ image_input = gr.Image(
58
+ source="upload",
59
+ tool="editor",
60
+ label="Upload Tomato Leaf Image",
61
+ type="pil"
62
+ )
63
+ # Camera input for real-time preview
64
+ camera_input = gr.Image(
65
+ source="camera",
66
+ label="Or use Camera Preview",
67
+ type="pil"
68
+ )
69
+ submit = gr.Button("Analyze")
70
+
71
+ # Output textbox for model result
72
+ output = gr.Textbox(label="Result")
73
+
74
+ # Combine image from either input before processing
75
+ combined_image = gr.Image(visible=False)
76
+ # When submit is clicked, combine the two images and then process the image.
77
+ submit.click(
78
+ fn=lambda uploaded, camera, ver: process_image(combine_images(uploaded, camera), ver),
79
+ inputs=[image_input, camera_input, version],
80
+ outputs=output
81
+ )
82
+
83
+ # Note on theme selection (this is a placeholder: dynamic theme switching may require extra custom code)
84
+ gr.Markdown(
85
+ "Note: The theme toggle is currently a placeholder. "
86
+ "To apply light/dark themes dynamically, consider adding custom CSS or reloading the interface."
87
+ )
88
+
89
+ demo.launch()