itbetyar commited on
Commit
c252543
·
verified ·
1 Parent(s): 4e0bd89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -19,16 +19,22 @@ def predict_fn(img):
19
  out = model(img)
20
  probabilities = torch.nn.functional.softmax(out[0], dim=0)
21
  values, indices = torch.topk(probabilities, k=5)
22
- return {LABELS[i]: v.item() for i, v in zip(indices, values)}
 
 
 
 
 
 
23
 
24
  # HTML for the header
25
  header_html = """
26
  <div style="text-align: center; max-width: 650px; margin: 0 auto;">
27
  <img src="https://huggingface.co/spaces/itbetyar/gradio-demo/resolve/main/imgclass.webp" alt="Header Image" style="max-width: 100%; height: auto; margin: 20px 0;">
28
- <h1 style="color: #424C5B; font-size: 2.5em;">IT Betyár | Resnet Image Classifier</h1>
29
  <p style="color: #FFFFFF; font-size: 1.2em;">
30
- Üdvözöljük képosztályozónkban! Ez az eszköz egy ImageNeten betanított ResNet50 modellt használ
31
- a képek osztályozására. Tölts fel egy képet, és megmutatjuk az 5 legjobb predikciót.
32
  </p>
33
  </div>
34
  """
@@ -38,14 +44,24 @@ with gr.Blocks() as demo:
38
 
39
  with gr.Row():
40
  with gr.Column():
41
- input_image = gr.Image(type='pil')
42
 
43
  with gr.Row():
44
  clear_btn = gr.Button("Reset")
45
  classify_btn = gr.Button("Mehet")
46
 
47
- # Add examples section properly
48
- gr.Examples(
 
 
 
 
 
 
 
 
 
 
49
  examples=[
50
  "imgs/lion.jpg",
51
  "imgs/car.jpg",
@@ -56,13 +72,10 @@ with gr.Blocks() as demo:
56
  "imgs/alligator.jpg",
57
  "imgs/arc.jpg"
58
  ],
59
- inputs=input_image,
60
  )
61
-
62
- with gr.Column():
63
- output = gr.Label()
64
-
65
- classify_btn.click(predict_fn, inputs=input_image, outputs=output)
66
- clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
67
 
68
  demo.launch()
 
19
  out = model(img)
20
  probabilities = torch.nn.functional.softmax(out[0], dim=0)
21
  values, indices = torch.topk(probabilities, k=5)
22
+
23
+ # Get the top labels and select only the first part of the label
24
+ top_labels = [LABELS[i].split(',')[0] for i in indices]
25
+
26
+ # Return only the label and its probability
27
+ return {top_labels[i]: values[i].item() for i in range(5)}
28
+
29
 
30
  # HTML for the header
31
  header_html = """
32
  <div style="text-align: center; max-width: 650px; margin: 0 auto;">
33
  <img src="https://huggingface.co/spaces/itbetyar/gradio-demo/resolve/main/imgclass.webp" alt="Header Image" style="max-width: 100%; height: auto; margin: 20px 0;">
34
+ <h1 style="color: #67768c; font-size: 2.5em;">IT Betyár | Resnet 50 Image Classifier</h1>
35
  <p style="color: #FFFFFF; font-size: 1.2em;">
36
+ Üdvözlünk képosztályozónkban! Ez a minta app egy <b>ResNet50</b> A.I. modellt használ
37
+ a képek osztályozására. Tölts fel egy képet, és megmutatjuk a három legjobb predikciót.
38
  </p>
39
  </div>
40
  """
 
44
 
45
  with gr.Row():
46
  with gr.Column():
47
+ input_image = gr.Image(type='pil', label="Tölts fel egy képet...", width=500, height=400, sources=["upload","webcam"])
48
 
49
  with gr.Row():
50
  clear_btn = gr.Button("Reset")
51
  classify_btn = gr.Button("Mehet")
52
 
53
+
54
+ with gr.Column():
55
+ gr.HTML("""<div style="background: #27272A; padding:15px; font-size:16px;">
56
+ Alább láthatod a kép osztályozás eredményét</div>""")
57
+ output = gr.Label(num_top_classes=3, label="A kép osztálya:")
58
+
59
+ classify_btn.click(predict_fn, inputs=input_image, outputs=output)
60
+ clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
61
+
62
+ # Add examples section properly
63
+ with gr.Row():
64
+ gr.Examples(
65
  examples=[
66
  "imgs/lion.jpg",
67
  "imgs/car.jpg",
 
72
  "imgs/alligator.jpg",
73
  "imgs/arc.jpg"
74
  ],
75
+ inputs=input_image, label="Betölthető minták"
76
  )
77
+
78
+ with gr.Row():
79
+ gr.HTML("""<div style="margin:100px;"></div>""")
 
 
 
80
 
81
  demo.launch()