Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,24 @@
|
|
| 1 |
import spaces, os
|
| 2 |
import gradio as gr
|
| 3 |
-
from kokoro import KPipeline
|
| 4 |
-
from qwen_vl_utils import process_vision_info
|
| 5 |
|
|
|
|
| 6 |
from demo.infer import LiveCCDemoInfer
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
infer = None
|
| 20 |
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
gr.Markdown("## LiveCC Conversation and Real-Time Commentary - Gradio Demo")
|
|
@@ -57,15 +59,15 @@ with gr.Blocks() as demo:
|
|
| 57 |
|
| 58 |
@spaces.GPU
|
| 59 |
def gr_chatinterface_fn(message, history, state, video_path, mode):
|
| 60 |
-
global
|
| 61 |
yield '(initializing model, thanks for waiting...)', state
|
| 62 |
-
if
|
| 63 |
-
|
| 64 |
state['video_path'] = video_path
|
| 65 |
yield '(finished initialization, responding...)', state
|
| 66 |
if mode != 'Conversation':
|
| 67 |
yield 'waiting video input...', state
|
| 68 |
-
response, _ =
|
| 69 |
yield response, {}
|
| 70 |
|
| 71 |
def gr_chatinterface_chatbot_clear_fn():
|
|
|
|
| 1 |
import spaces, os
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
from kokoro import KPipeline
|
| 5 |
from demo.infer import LiveCCDemoInfer
|
| 6 |
|
| 7 |
+
class GradioBackend:
|
| 8 |
+
waiting_video_response = 'Waiting for video input...'
|
| 9 |
+
not_found_video_response = 'Video does not exist...'
|
| 10 |
+
mode2api = {
|
| 11 |
+
'Real-Time Commentary': 'live_cc',
|
| 12 |
+
'Conversation': 'video_qa'
|
| 13 |
+
}
|
| 14 |
+
def __init__(self, model_path: str = 'chenjoya/LiveCC-7B-Instruct'):
|
| 15 |
+
self.infer = LiveCCDemoInfer(model_path)
|
| 16 |
+
self.audio_pipeline = KPipeline(lang_code='a')
|
| 17 |
+
|
| 18 |
+
def __call__(self, query: str = None, state: dict = {}, mode: str = 'Real-Time Commentary', **kwargs):
|
| 19 |
+
return getattr(self.infer, self.mode2api[mode])(query=query, state=state, **kwargs)
|
| 20 |
|
| 21 |
+
gradio_backend = None
|
|
|
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
gr.Markdown("## LiveCC Conversation and Real-Time Commentary - Gradio Demo")
|
|
|
|
| 59 |
|
| 60 |
@spaces.GPU
|
| 61 |
def gr_chatinterface_fn(message, history, state, video_path, mode):
|
| 62 |
+
global gradio_backend
|
| 63 |
yield '(initializing model, thanks for waiting...)', state
|
| 64 |
+
if gradio_backend is None:
|
| 65 |
+
gradio_backend = GradioBackend()
|
| 66 |
state['video_path'] = video_path
|
| 67 |
yield '(finished initialization, responding...)', state
|
| 68 |
if mode != 'Conversation':
|
| 69 |
yield 'waiting video input...', state
|
| 70 |
+
response, _ = gradio_backend.video_qa(query=message, state=state)
|
| 71 |
yield response, {}
|
| 72 |
|
| 73 |
def gr_chatinterface_chatbot_clear_fn():
|