KingNish commited on
Commit
25d5485
·
verified ·
1 Parent(s): 5bf9ae1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
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, media_type, text_input=None):
 
 
 
 
 
 
 
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
- input_video = gr.Video(label="Input Video")
100
- text_input_video = gr.Textbox(label="Question")
101
- submit_btn_video = gr.Button(value="Submit")
102
  with gr.Column():
103
- output_text_video = gr.Textbox(label="Output Text")
104
- type = gr.State("video")
105
 
106
- submit_btn_video.click(qwen_inference, [input_video, type, text_input_video], [output_text_video])
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)