Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,6 @@ import subprocess
|
|
8 |
from datetime import datetime
|
9 |
import numpy as np
|
10 |
import os
|
11 |
-
from moviepy.editor import VideoFileClip
|
12 |
-
import loadimg
|
13 |
|
14 |
# Install flash-attn
|
15 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
@@ -21,35 +19,16 @@ processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
|
|
21 |
|
22 |
DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)"
|
23 |
|
24 |
-
# Helper function to save media and return path
|
25 |
-
def save_media_and_get_path(media, media_type):
|
26 |
-
if media is None:
|
27 |
-
gr.Warning(f"No {media_type} provided. Please upload a {media_type} before submitting.")
|
28 |
-
raise ValueError(f"No {media_type} provided.")
|
29 |
-
|
30 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
31 |
-
filename = f"{media_type}_{timestamp}.{'png' if media_type == 'image' else 'webm'}"
|
32 |
-
|
33 |
-
if media_type == "image":
|
34 |
-
media = loadimg(media, "pil")
|
35 |
-
media.save(filename)
|
36 |
-
elif media_type == "video":
|
37 |
-
VideoFileClip(media).write_videofile(filename, fps=8, audio=False)
|
38 |
-
return os.path.abspath(filename)
|
39 |
-
|
40 |
-
|
41 |
@spaces.GPU
|
42 |
-
def qwen_inference(
|
43 |
-
|
44 |
image_extensions = Image.registered_extensions()
|
45 |
-
if
|
46 |
media_type = "image"
|
47 |
-
elif
|
48 |
media_type = "video"
|
49 |
else:
|
50 |
raise ValueError("Unsupported media type. Please upload an image or video.")
|
51 |
-
|
52 |
-
media_path = media
|
53 |
|
54 |
messages = [
|
55 |
{
|
|
|
8 |
from datetime import datetime
|
9 |
import numpy as np
|
10 |
import os
|
|
|
|
|
11 |
|
12 |
# Install flash-attn
|
13 |
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
|
|
|
19 |
|
20 |
DESCRIPTION = "[Qwen2-VL-7B Demo](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)"
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
@spaces.GPU
|
23 |
+
def qwen_inference(media_path, text_input=None):
|
24 |
+
|
25 |
image_extensions = Image.registered_extensions()
|
26 |
+
if media_path.endswith(tuple([i for i, f in image_extensions.items()])):
|
27 |
media_type = "image"
|
28 |
+
elif media_path.endswith(("avi", "mp4", "mov", "mkv", "flv", "wmv", "mjpeg", "wav", "gif", "webm", "m4v", "3gp")): # Check if it's a video path
|
29 |
media_type = "video"
|
30 |
else:
|
31 |
raise ValueError("Unsupported media type. Please upload an image or video.")
|
|
|
|
|
32 |
|
33 |
messages = [
|
34 |
{
|