Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,13 +5,14 @@
|
|
5 |
import os
|
6 |
import numpy as np
|
7 |
from urllib3.exceptions import HTTPError
|
8 |
-
os.system('pip install dashscope modelscope -U')
|
9 |
|
10 |
from argparse import ArgumentParser
|
11 |
from pathlib import Path
|
12 |
|
13 |
import copy
|
14 |
import gradio as gr
|
|
|
15 |
import os
|
16 |
import re
|
17 |
import secrets
|
@@ -21,7 +22,14 @@ from http import HTTPStatus
|
|
21 |
from dashscope import MultiModalConversation
|
22 |
import dashscope
|
23 |
API_KEY = os.environ['API_KEY']
|
|
|
|
|
|
|
|
|
24 |
dashscope.api_key = API_KEY
|
|
|
|
|
|
|
25 |
|
26 |
REVISION = 'v1.0.4'
|
27 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
@@ -81,6 +89,12 @@ def _remove_image_special(text):
|
|
81 |
text = text.replace('<ref>', '').replace('</ref>', '')
|
82 |
return re.sub(r'<box>.*?(</box>|$)', '', text)
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
def _launch_demo(args):
|
85 |
uploaded_file_dir = os.environ.get("GRADIO_TEMP_DIR") or str(
|
86 |
Path(tempfile.gettempdir()) / "gradio"
|
@@ -100,7 +114,13 @@ def _launch_demo(args):
|
|
100 |
content = []
|
101 |
for q, a in history_cp:
|
102 |
if isinstance(q, (tuple, list)):
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
else:
|
105 |
content.append({'text': q})
|
106 |
messages.append({'role': 'user', 'content': content})
|
@@ -196,7 +216,7 @@ def _launch_demo(args):
|
|
196 |
task_history = gr.State([])
|
197 |
|
198 |
with gr.Row():
|
199 |
-
addfile_btn = gr.UploadButton("π Upload (δΈδΌ ζδ»Ά)", file_types=["image"])
|
200 |
submit_btn = gr.Button("π Submit (ει)")
|
201 |
regen_btn = gr.Button("π€οΈ Regenerate (ιθ―)")
|
202 |
empty_bin = gr.Button("π§Ή Clear History (ζΈ
ι€εε²)")
|
|
|
5 |
import os
|
6 |
import numpy as np
|
7 |
from urllib3.exceptions import HTTPError
|
8 |
+
os.system('pip install dashscope modelscope oss2 -U')
|
9 |
|
10 |
from argparse import ArgumentParser
|
11 |
from pathlib import Path
|
12 |
|
13 |
import copy
|
14 |
import gradio as gr
|
15 |
+
import oss2
|
16 |
import os
|
17 |
import re
|
18 |
import secrets
|
|
|
22 |
from dashscope import MultiModalConversation
|
23 |
import dashscope
|
24 |
API_KEY = os.environ['API_KEY']
|
25 |
+
ENDPOINT = os.environ['ENDPOINT']
|
26 |
+
AK_ID = os.environ['AK_ID']
|
27 |
+
AK = os.environ['AK']
|
28 |
+
BUCKET_NAME = os.environ['BUCKET_NAME']
|
29 |
dashscope.api_key = API_KEY
|
30 |
+
endpoint = ENDPOINT
|
31 |
+
auth = oss2.Auth(AK_ID, AK)
|
32 |
+
bucket = oss2.Bucket(auth, endpoint, BUCKET_NAME)
|
33 |
|
34 |
REVISION = 'v1.0.4'
|
35 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
|
|
89 |
text = text.replace('<ref>', '').replace('</ref>', '')
|
90 |
return re.sub(r'<box>.*?(</box>|$)', '', text)
|
91 |
|
92 |
+
|
93 |
+
def is_video_file(filename):
|
94 |
+
video_extensions = ['.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv', '.webm', '.mpeg']
|
95 |
+
return any(filename.lower().endswith(ext) for ext in video_extensions)
|
96 |
+
|
97 |
+
|
98 |
def _launch_demo(args):
|
99 |
uploaded_file_dir = os.environ.get("GRADIO_TEMP_DIR") or str(
|
100 |
Path(tempfile.gettempdir()) / "gradio"
|
|
|
114 |
content = []
|
115 |
for q, a in history_cp:
|
116 |
if isinstance(q, (tuple, list)):
|
117 |
+
if is_video_file(q[0]):
|
118 |
+
key = q[0].split(os.sep)[-2]
|
119 |
+
bucket.put_object_from_file(key, q[0])
|
120 |
+
url = bucket.sign_url('GET', key, 3600)
|
121 |
+
content.append({'video': url})
|
122 |
+
else:
|
123 |
+
content.append({'image': f'file://{q[0]}'})
|
124 |
else:
|
125 |
content.append({'text': q})
|
126 |
messages.append({'role': 'user', 'content': content})
|
|
|
216 |
task_history = gr.State([])
|
217 |
|
218 |
with gr.Row():
|
219 |
+
addfile_btn = gr.UploadButton("π Upload (δΈδΌ ζδ»Ά)", file_types=["image", "video"])
|
220 |
submit_btn = gr.Button("π Submit (ει)")
|
221 |
regen_btn = gr.Button("π€οΈ Regenerate (ιθ―)")
|
222 |
empty_bin = gr.Button("π§Ή Clear History (ζΈ
ι€εε²)")
|