sử dụng các tab trong gr.Blocks() thay vì sử dụng gr.TabbedInterface
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from PIL import Image
|
|
4 |
import torch
|
5 |
import tempfile
|
6 |
import os
|
7 |
-
|
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.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
image_output_score = gr.Textbox(label="Confidence Score")
|
52 |
|
53 |
-
|
54 |
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
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()
|