Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
image_class_pipe = pipeline(task="image-classification", model="google/vit-large-patch16-224")
|
6 |
+
video_class_pipe = pipeline(task="video-classification", model="nateraw/videomae-base-finetuned-ucf101-subset")
|
7 |
+
depth_estimator = pipeline(task="depth-estimation", model="Intel/dpt-large")
|
8 |
+
image_caption = pipeline("image-to-text",model="Salesforce/blip-image-captioning-base")
|
9 |
+
|
10 |
+
def classify_image_func(arr):
|
11 |
+
img = Image.fromarray(arr)
|
12 |
+
image_result = image_class_pipe(img)
|
13 |
+
return image_result[0]["label"]
|
14 |
+
|
15 |
+
def classify_video_func(vid):
|
16 |
+
video_result = video_class_pipe(vid)
|
17 |
+
return video_result
|
18 |
+
|
19 |
+
def estimate_depth_func(arr):
|
20 |
+
img = Image.fromarray(arr)
|
21 |
+
depth_result = depth_estimator(img)
|
22 |
+
return depth_result["depth"]
|
23 |
+
|
24 |
+
def blip_captioning_func(arr):
|
25 |
+
img = Image.fromarray(arr)
|
26 |
+
image_caption_result = image_caption(img, max_new_tokens=500)
|
27 |
+
return image_caption_result[0]["generated_text"]
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("# AI Methods")
|
31 |
+
|
32 |
+
with gr.Tab("Media Classification"):
|
33 |
+
gr.Markdown("# Image Classification")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
classify_image_input = gr.Image(width=340, height=340)
|
37 |
+
with gr.Row():
|
38 |
+
classify_image_btn = gr.Button("Classify Image")
|
39 |
+
classify_image_output = gr.Textbox(label="Result")
|
40 |
+
|
41 |
+
classify_image_btn.click(fn=classify_image_func, inputs=[classify_image_input], outputs=[classify_image_output])
|
42 |
+
|
43 |
+
gr.Markdown("# Video Classification")
|
44 |
+
|
45 |
+
with gr.Row():
|
46 |
+
classify_video_input = gr.Video(width=340, height=340)
|
47 |
+
with gr.Row():
|
48 |
+
classify_video_btn = gr.Button("Classify Video")
|
49 |
+
classify_video_output = gr.Textbox(label="Result")
|
50 |
+
|
51 |
+
classify_video_btn.click(fn=classify_video_func, inputs=[classify_video_input], outputs=[classify_video_output])
|
52 |
+
|
53 |
+
with gr.Tab("Depth"):
|
54 |
+
gr.Markdown("# Depth Estimation")
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
depth_estimation_input = gr.Image(width=260, height=260)
|
58 |
+
with gr.Row():
|
59 |
+
depth_estimation_btn = gr.Button("Estimate Depth")
|
60 |
+
with gr.Row():
|
61 |
+
depth_estimation_output = gr.Image()
|
62 |
+
|
63 |
+
depth_estimation_btn.click(fn=estimate_depth_func, inputs=[depth_estimation_input], outputs=[depth_estimation_output])
|
64 |
+
|
65 |
+
with gr.Tab("BLIP Captioning"):
|
66 |
+
gr.Markdown("# BLIP Captioning")
|
67 |
+
|
68 |
+
with gr.Row():
|
69 |
+
blip_input = gr.Image(width=260, height=260)
|
70 |
+
with gr.Row():
|
71 |
+
blip_btn = gr.Button("BLIP Caption")
|
72 |
+
blip_output = gr.Textbox(label="Caption")
|
73 |
+
|
74 |
+
blip_btn.click(fn=blip_captioning_func, inputs=[blip_input], outputs=[blip_output])
|
75 |
+
|
76 |
+
demo.launch(debug=True)
|