fossbk commited on
Commit
366b65f
·
verified ·
1 Parent(s): c50ae26

sử dụng các tab trong gr.Blocks() thay vì sử dụng gr.TabbedInterface

Browse files
Files changed (1) hide show
  1. app.py +20 -21
app.py CHANGED
@@ -4,7 +4,7 @@ from PIL import Image
4
  import torch
5
  import tempfile
6
  import os
7
- #from moviepy.editor import VideoFileClip
8
 
9
  # Kiểm tra thiết bị sử dụng GPU hay CPU
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -39,31 +39,30 @@ def classify_video(video, model_name):
39
  result = classifier(image)
40
  return result[0]['label'], result[0]['score']
41
 
42
- # Giao diện Gradio
43
  with gr.Blocks() as demo:
44
- with gr.TabbedInterface() as tabs:
45
- with gr.TabItem("Image Classification"):
46
- gr.Markdown("### Upload an image for classification")
47
- with gr.Row():
48
- model_choice_image = gr.Dropdown(choices=["ViT", "ResNet"], label="Choose a Model", value="ViT")
49
- image_input = gr.Image(type="pil", label="Upload Image")
50
- image_output_label = gr.Textbox(label="Prediction")
51
- image_output_score = gr.Textbox(label="Confidence Score")
52
 
53
- classify_image_button = gr.Button("Classify Image")
54
 
55
- classify_image_button.click(classify_image, inputs=[image_input, model_choice_image], outputs=[image_output_label, image_output_score])
56
 
57
- with gr.TabItem("Video Classification"):
58
- gr.Markdown("### Upload a video for classification")
59
- with gr.Row():
60
- model_choice_video = gr.Dropdown(choices=["ViT", "ResNet"], label="Choose a Model", value="ViT")
61
- video_input = gr.Video(label="Upload Video")
62
- video_output_label = gr.Textbox(label="Prediction")
63
- video_output_score = gr.Textbox(label="Confidence Score")
64
 
65
- classify_video_button = gr.Button("Classify Video")
66
 
67
- classify_video_button.click(classify_video, inputs=[video_input, model_choice_video], outputs=[video_output_label, video_output_score])
68
 
69
  demo.launch()
 
4
  import torch
5
  import tempfile
6
  import os
7
+ from moviepy.editor import VideoFileClip
8
 
9
  # Kiểm tra thiết bị sử dụng GPU hay CPU
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
39
  result = classifier(image)
40
  return result[0]['label'], result[0]['score']
41
 
42
+ # Giao diện Gradio với các tab
43
  with gr.Blocks() as demo:
44
+ with gr.Tab("Image Classification"):
45
+ gr.Markdown("### Upload an image for classification")
46
+ with gr.Row():
47
+ model_choice_image = gr.Dropdown(choices=["ViT", "ResNet"], label="Choose a Model", value="ViT")
48
+ image_input = gr.Image(type="pil", label="Upload Image")
49
+ image_output_label = gr.Textbox(label="Prediction")
50
+ image_output_score = gr.Textbox(label="Confidence Score")
 
51
 
52
+ classify_image_button = gr.Button("Classify Image")
53
 
54
+ classify_image_button.click(classify_image, inputs=[image_input, model_choice_image], outputs=[image_output_label, image_output_score])
55
 
56
+ with gr.Tab("Video Classification"):
57
+ gr.Markdown("### Upload a video for classification")
58
+ with gr.Row():
59
+ model_choice_video = gr.Dropdown(choices=["ViT", "ResNet"], label="Choose a Model", value="ViT")
60
+ video_input = gr.Video(label="Upload Video")
61
+ video_output_label = gr.Textbox(label="Prediction")
62
+ video_output_score = gr.Textbox(label="Confidence Score")
63
 
64
+ classify_video_button = gr.Button("Classify Video")
65
 
66
+ classify_video_button.click(classify_video, inputs=[video_input, model_choice_video], outputs=[video_output_label, video_output_score])
67
 
68
  demo.launch()