Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,14 @@ def save_media_and_get_path(media, media_type):
|
|
37 |
|
38 |
|
39 |
@spaces.GPU
|
40 |
-
def qwen_inference(media,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
media_path = save_media_and_get_path(media, media_type)
|
42 |
|
43 |
messages = [
|
@@ -81,28 +88,15 @@ css = """
|
|
81 |
with gr.Blocks(css=css) as demo:
|
82 |
gr.Markdown(DESCRIPTION)
|
83 |
|
84 |
-
with gr.Tab(label="Image Input"):
|
85 |
-
with gr.Row():
|
86 |
-
with gr.Column():
|
87 |
-
input_img = gr.Image(label="Input Picture", type="pil")
|
88 |
-
text_input_image = gr.Textbox(label="Question")
|
89 |
-
submit_btn_image = gr.Button(value="Submit")
|
90 |
-
with gr.Column():
|
91 |
-
output_text_image = gr.Textbox(label="Output Text")
|
92 |
-
type = gr.State("image")
|
93 |
-
|
94 |
-
submit_btn_image.click(qwen_inference, [input_img, type, text_input_image], [output_text_image])
|
95 |
-
|
96 |
-
with gr.Tab(label="Video Input"):
|
97 |
with gr.Row():
|
98 |
with gr.Column():
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
with gr.Column():
|
103 |
-
|
104 |
-
type = gr.State("video")
|
105 |
|
106 |
-
|
107 |
|
108 |
demo.launch(debug=True)
|
|
|
37 |
|
38 |
|
39 |
@spaces.GPU
|
40 |
+
def qwen_inference(media, text_input=None):
|
41 |
+
if isinstance(media, Image.Image):
|
42 |
+
media_type = "image"
|
43 |
+
elif isinstance(media, str) and media.endswith((".mp4", ".webm", ".avi")): # Check if it's a video path
|
44 |
+
media_type = "video"
|
45 |
+
else:
|
46 |
+
raise ValueError("Unsupported media type. Please upload an image or video.")
|
47 |
+
|
48 |
media_path = save_media_and_get_path(media, media_type)
|
49 |
|
50 |
messages = [
|
|
|
88 |
with gr.Blocks(css=css) as demo:
|
89 |
gr.Markdown(DESCRIPTION)
|
90 |
|
91 |
+
with gr.Tab(label="Image/Video Input"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
with gr.Row():
|
93 |
with gr.Column():
|
94 |
+
input_media = gr.Upload(label="Upload Image or Video", type="file")
|
95 |
+
text_input = gr.Textbox(label="Question")
|
96 |
+
submit_btn = gr.Button(value="Submit")
|
97 |
with gr.Column():
|
98 |
+
output_text = gr.Textbox(label="Output Text")
|
|
|
99 |
|
100 |
+
submit_btn.click(qwen_inference, [input_media, text_input], [output_text])
|
101 |
|
102 |
demo.launch(debug=True)
|