Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,6 @@ label_map = {
|
|
18 |
# Add more if needed
|
19 |
}
|
20 |
|
21 |
-
# 🧠 Classification function
|
22 |
def classify_mushroom(image: Image.Image):
|
23 |
print("✅ classify_mushroom: NEW VERSION")
|
24 |
|
@@ -32,15 +31,14 @@ def classify_mushroom(image: Image.Image):
|
|
32 |
score = round(result['score'] * 100, 2)
|
33 |
|
34 |
prediction_en, prediction_th = label_map.get(label, ("Unknown", "ไม่ทราบ"))
|
35 |
-
print("✅ RETURNING:", prediction_en, prediction_th, f"{score:.2f}%"
|
36 |
-
|
37 |
-
return prediction_en, prediction_th, f"{score:.2f}%", label
|
38 |
|
39 |
except Exception as e:
|
40 |
print(f"❌ Error: {e}")
|
41 |
-
return "Error", "ผิดพลาด", "N/A"
|
42 |
|
43 |
-
#
|
44 |
if __name__ == "__main__":
|
45 |
with gr.Blocks() as demo:
|
46 |
gr.Markdown("## 🍄 Mushroom Safety Classifier")
|
@@ -52,14 +50,13 @@ if __name__ == "__main__":
|
|
52 |
label_en = gr.Textbox(label="🧠 Prediction (English)")
|
53 |
label_th = gr.Textbox(label="🗣️ คำทำนาย (ภาษาไทย)")
|
54 |
confidence = gr.Textbox(label="📶 Confidence Score")
|
55 |
-
label_raw = gr.Textbox(label="🏷️ Predicted Mushroom Name")
|
56 |
|
57 |
classify_btn = gr.Button("🔍 Classify")
|
58 |
|
59 |
classify_btn.click(
|
60 |
fn=classify_mushroom,
|
61 |
inputs=image_input,
|
62 |
-
outputs=[label_en, label_th, confidence
|
63 |
)
|
64 |
|
65 |
demo.launch()
|
|
|
18 |
# Add more if needed
|
19 |
}
|
20 |
|
|
|
21 |
def classify_mushroom(image: Image.Image):
|
22 |
print("✅ classify_mushroom: NEW VERSION")
|
23 |
|
|
|
31 |
score = round(result['score'] * 100, 2)
|
32 |
|
33 |
prediction_en, prediction_th = label_map.get(label, ("Unknown", "ไม่ทราบ"))
|
34 |
+
print("✅ RETURNING:", prediction_en, prediction_th, f"{score:.2f}%")
|
35 |
+
return prediction_en, prediction_th, f"{score:.2f}%"
|
|
|
36 |
|
37 |
except Exception as e:
|
38 |
print(f"❌ Error: {e}")
|
39 |
+
return "Error", "ผิดพลาด", "N/A"
|
40 |
|
41 |
+
# ✅ Put Gradio inside the main block
|
42 |
if __name__ == "__main__":
|
43 |
with gr.Blocks() as demo:
|
44 |
gr.Markdown("## 🍄 Mushroom Safety Classifier")
|
|
|
50 |
label_en = gr.Textbox(label="🧠 Prediction (English)")
|
51 |
label_th = gr.Textbox(label="🗣️ คำทำนาย (ภาษาไทย)")
|
52 |
confidence = gr.Textbox(label="📶 Confidence Score")
|
|
|
53 |
|
54 |
classify_btn = gr.Button("🔍 Classify")
|
55 |
|
56 |
classify_btn.click(
|
57 |
fn=classify_mushroom,
|
58 |
inputs=image_input,
|
59 |
+
outputs=[label_en, label_th, confidence]
|
60 |
)
|
61 |
|
62 |
demo.launch()
|