prakasa1234 commited on
Commit
2b3c5dc
·
verified ·
1 Parent(s): 1092238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -24
app.py CHANGED
@@ -6,16 +6,16 @@ import gradio as gr
6
  import traceback
7
 
8
  # -----------------------------
9
- # 1. YOLO model path
10
  # -----------------------------
11
  YOLO_MODEL_PATH = "best.pt"
12
  yolo_model = YOLO(YOLO_MODEL_PATH)
13
  yolo_model.eval()
14
 
15
  # -----------------------------
16
- # 2. Reference alphabet image
17
  # -----------------------------
18
- REFERENCE_IMAGE_PATH = "asl_alphabet.webp" # Web-friendly format
19
  reference_img = cv2.imread(REFERENCE_IMAGE_PATH)
20
  reference_img = cv2.cvtColor(reference_img, cv2.COLOR_BGR2RGB)
21
 
@@ -29,7 +29,6 @@ def predict_asl(image):
29
 
30
  img = image.copy()
31
 
32
- # YOLO prediction
33
  results = yolo_model.predict(img, imgsz=320, verbose=False)[0]
34
  pred_idx = results.probs.top1
35
  pred_label = results.names[pred_idx]
@@ -47,10 +46,7 @@ def predict_asl(image):
47
  cv2.LINE_AA
48
  )
49
 
50
- # Combine uploaded image and reference alphabet side by side
51
- combined_img = np.hstack([cv2.cvtColor(img, cv2.COLOR_BGR2RGB), reference_img])
52
-
53
- return combined_img, pred_label, round(confidence, 2)
54
 
55
  except Exception as e:
56
  print("❌ Error in predict_asl:", e)
@@ -58,23 +54,29 @@ def predict_asl(image):
58
  return image, "Error", 0.0
59
 
60
  # -----------------------------
61
- # 4. Gradio Interface
62
  # -----------------------------
63
- title = "🖐️ ASL Letter Classifier"
64
- description = "Upload a hand sign image and compare it with the full ASL alphabet."
 
65
 
66
- iface = gr.Interface(
67
- fn=predict_asl,
68
- inputs=gr.Image(type="numpy", label="Upload your ASL Letter"),
69
- outputs=[
70
- gr.Image(type="numpy", label="Your Image with Prediction & Alphabet Reference"),
71
- gr.Textbox(label="Predicted Letter"),
72
- gr.Textbox(label="Confidence")
73
- ],
74
- title=title,
75
- description=description,
76
- allow_flagging="never"
77
- )
 
 
 
 
 
78
 
79
  if __name__ == "__main__":
80
- iface.launch(share=True)
 
6
  import traceback
7
 
8
  # -----------------------------
9
+ # 1. YOLO model
10
  # -----------------------------
11
  YOLO_MODEL_PATH = "best.pt"
12
  yolo_model = YOLO(YOLO_MODEL_PATH)
13
  yolo_model.eval()
14
 
15
  # -----------------------------
16
+ # 2. Reference alphabet image (WebP)
17
  # -----------------------------
18
+ REFERENCE_IMAGE_PATH = "asl_alphabet.webp"
19
  reference_img = cv2.imread(REFERENCE_IMAGE_PATH)
20
  reference_img = cv2.cvtColor(reference_img, cv2.COLOR_BGR2RGB)
21
 
 
29
 
30
  img = image.copy()
31
 
 
32
  results = yolo_model.predict(img, imgsz=320, verbose=False)[0]
33
  pred_idx = results.probs.top1
34
  pred_label = results.names[pred_idx]
 
46
  cv2.LINE_AA
47
  )
48
 
49
+ return cv2.cvtColor(img, cv2.COLOR_BGR2RGB), pred_label, round(confidence, 2)
 
 
 
50
 
51
  except Exception as e:
52
  print("❌ Error in predict_asl:", e)
 
54
  return image, "Error", 0.0
55
 
56
  # -----------------------------
57
+ # 4. Gradio Layout
58
  # -----------------------------
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("## 🖐️ ASL Letter Classifier")
61
+ gr.Markdown("Upload a hand sign image and see the predicted letter and confidence. The full ASL alphabet is always shown on the left as a reference.")
62
 
63
+ with gr.Row():
64
+ # Left column: reference alphabet
65
+ with gr.Column(scale=1):
66
+ gr.Image(value=reference_img, type="numpy", label="ASL Alphabet Reference")
67
+
68
+ # Right column: upload & prediction
69
+ with gr.Column(scale=2):
70
+ input_image = gr.Image(type="numpy", label="Upload your ASL Letter")
71
+ output_image = gr.Image(type="numpy", label="Prediction")
72
+ pred_text = gr.Textbox(label="Predicted Letter")
73
+ confidence_text = gr.Textbox(label="Confidence")
74
+
75
+ input_image.change(
76
+ fn=predict_asl,
77
+ inputs=input_image,
78
+ outputs=[output_image, pred_text, confidence_text]
79
+ )
80
 
81
  if __name__ == "__main__":
82
+ demo.launch(share=True)