Spaces:
Running
Running
Upload 3 files
#3
by
shivakumar4147
- opened
- app.py +28 -147
- final_model.h5 +3 -0
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,147 +1,28 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
() => {
|
30 |
-
document.body.classList.toggle('dark');
|
31 |
-
document.querySelector('gradio-app').style.backgroundColor = 'var(--color-background-primary)'
|
32 |
-
}
|
33 |
-
""",
|
34 |
-
)
|
35 |
-
|
36 |
-
name = gr.Textbox(
|
37 |
-
label="Name",
|
38 |
-
info="Full name, including middle name. No special characters.",
|
39 |
-
placeholder="John Doe",
|
40 |
-
value="John Doe",
|
41 |
-
interactive=True,
|
42 |
-
)
|
43 |
-
|
44 |
-
with gr.Row():
|
45 |
-
slider1 = gr.Slider(label="Slider 1")
|
46 |
-
slider2 = gr.Slider(label="Slider 2")
|
47 |
-
gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")
|
48 |
-
|
49 |
-
with gr.Row():
|
50 |
-
with gr.Column(variant="panel", scale=1):
|
51 |
-
gr.Markdown("## Panel 1")
|
52 |
-
radio = gr.Radio(
|
53 |
-
["A", "B", "C"],
|
54 |
-
label="Radio",
|
55 |
-
info="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
56 |
-
)
|
57 |
-
drop = gr.Dropdown(["Option 1", "Option 2", "Option 3"], show_label=False)
|
58 |
-
drop_2 = gr.Dropdown(
|
59 |
-
["Option A", "Option B", "Option C"],
|
60 |
-
multiselect=True,
|
61 |
-
value=["Option A"],
|
62 |
-
label="Dropdown",
|
63 |
-
interactive=True,
|
64 |
-
)
|
65 |
-
check = gr.Checkbox(label="Go")
|
66 |
-
with gr.Column(variant="panel", scale=2):
|
67 |
-
img = gr.Image(
|
68 |
-
"https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpg", label="Image"
|
69 |
-
).style(height=320)
|
70 |
-
with gr.Row():
|
71 |
-
go_btn = gr.Button("Go", label="Primary Button", variant="primary")
|
72 |
-
clear_btn = gr.Button(
|
73 |
-
"Clear", label="Secondary Button", variant="secondary"
|
74 |
-
)
|
75 |
-
|
76 |
-
def go(*args):
|
77 |
-
time.sleep(3)
|
78 |
-
return "https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpg"
|
79 |
-
|
80 |
-
go_btn.click(go, [radio, drop, drop_2, check, name], img, api_name="go")
|
81 |
-
|
82 |
-
def clear():
|
83 |
-
time.sleep(0.2)
|
84 |
-
return None
|
85 |
-
|
86 |
-
clear_btn.click(clear, None, img)
|
87 |
-
|
88 |
-
with gr.Row():
|
89 |
-
btn1 = gr.Button("Button 1").style(size="sm")
|
90 |
-
btn2 = gr.UploadButton().style(size="sm")
|
91 |
-
stop_btn = gr.Button("Stop", label="Stop Button", variant="stop").style(
|
92 |
-
size="sm"
|
93 |
-
)
|
94 |
-
|
95 |
-
with gr.Row():
|
96 |
-
gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")
|
97 |
-
gr.JSON(
|
98 |
-
value={"a": 1, "b": 2, "c": {"test": "a", "test2": [1, 2, 3]}}, label="JSON"
|
99 |
-
)
|
100 |
-
gr.Label(value={"cat": 0.7, "dog": 0.2, "fish": 0.1})
|
101 |
-
gr.File()
|
102 |
-
with gr.Row():
|
103 |
-
gr.ColorPicker()
|
104 |
-
gr.Video("https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4")
|
105 |
-
gr.Gallery(
|
106 |
-
[
|
107 |
-
(
|
108 |
-
"https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpg",
|
109 |
-
"lion",
|
110 |
-
),
|
111 |
-
(
|
112 |
-
"https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.png",
|
113 |
-
"logo",
|
114 |
-
),
|
115 |
-
(
|
116 |
-
"https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
|
117 |
-
"tower",
|
118 |
-
),
|
119 |
-
]
|
120 |
-
).style(height="200px", grid=2)
|
121 |
-
|
122 |
-
with gr.Row():
|
123 |
-
with gr.Column(scale=2):
|
124 |
-
chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")
|
125 |
-
chat_btn = gr.Button("Add messages")
|
126 |
-
|
127 |
-
def chat(history):
|
128 |
-
time.sleep(2)
|
129 |
-
yield [["How are you?", "I am good."]]
|
130 |
-
|
131 |
-
chat_btn.click(
|
132 |
-
lambda history: history
|
133 |
-
+ [["How are you?", "I am good."]]
|
134 |
-
+ (time.sleep(2) or []),
|
135 |
-
chatbot,
|
136 |
-
chatbot,
|
137 |
-
)
|
138 |
-
with gr.Column(scale=1):
|
139 |
-
with gr.Accordion("Advanced Settings"):
|
140 |
-
gr.Markdown("Hello")
|
141 |
-
gr.Number(label="Chatbot control 1")
|
142 |
-
gr.Number(label="Chatbot control 2")
|
143 |
-
gr.Number(label="Chatbot control 3")
|
144 |
-
|
145 |
-
|
146 |
-
if __name__ == "__main__":
|
147 |
-
demo.queue().launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
import cv2
|
5 |
+
|
6 |
+
# Load model
|
7 |
+
model = tf.keras.models.load_model("model_244.h5")
|
8 |
+
|
9 |
+
def predict_image(image):
|
10 |
+
# Resize to 244x244
|
11 |
+
img = cv2.resize(image, (244, 244))
|
12 |
+
img = img.astype(np.float32) / 255.0
|
13 |
+
img = np.expand_dims(img, axis=0)
|
14 |
+
p = model.predict(img)[0][0]
|
15 |
+
risk = "High" if p > 0.7 else "Medium" if p > 0.4 else "Low"
|
16 |
+
return f"Risk: {risk} (Probability: {p:.3f})"
|
17 |
+
|
18 |
+
# Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict_image,
|
21 |
+
inputs=gr.Image(type="numpy"),
|
22 |
+
outputs="text",
|
23 |
+
title="Cancer Risk Detector (244×244)",
|
24 |
+
description="Upload an image to get a cancer risk prediction."
|
25 |
+
)
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ff8ac00211462b4b533154bae22362e5501838219a1dfb9eecf3bd8121ca533
|
3 |
+
size 24526712
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
opencv-python
|
3 |
+
numpy
|
4 |
+
gradio
|