Spaces:
Sleeping
Sleeping
Commit
·
b02b868
1
Parent(s):
a5e0d79
Add application main
Browse files- app.py +19 -15
- requirements.txt +4 -7
app.py
CHANGED
@@ -1,20 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import openvino_genai
|
3 |
import librosa
|
4 |
import numpy as np
|
5 |
-
from threading import Thread, Lock,Event
|
6 |
from scipy.ndimage import uniform_filter1d
|
7 |
from queue import Queue, Empty
|
8 |
|
9 |
-
|
10 |
# Initialize Mistral pipeline
|
11 |
mistral_pipe = openvino_genai.LLMPipeline("mistral-ov", device="CPU")
|
12 |
config = openvino_genai.GenerationConfig(
|
13 |
-
|
14 |
-
num_beams=1,
|
15 |
-
do_sample=False,
|
16 |
-
temperature=0.0,
|
17 |
-
top_p=1.0,
|
18 |
top_k=50
|
19 |
)
|
20 |
pipe_lock = Lock()
|
@@ -54,7 +65,6 @@ def transcribe(audio):
|
|
54 |
return whisper_pipe.generate(processed)
|
55 |
|
56 |
def stream_generator(message, history):
|
57 |
-
"""Original Mistral streaming function (unchanged)"""
|
58 |
response_queue = Queue()
|
59 |
completion_event = Event()
|
60 |
error_message = [None]
|
@@ -66,9 +76,7 @@ def stream_generator(message, history):
|
|
66 |
def generate():
|
67 |
try:
|
68 |
with pipe_lock:
|
69 |
-
|
70 |
mistral_pipe.generate(message, config, callback)
|
71 |
-
|
72 |
except Exception as e:
|
73 |
error_message[0] = str(e)
|
74 |
finally:
|
@@ -91,9 +99,7 @@ def stream_generator(message, history):
|
|
91 |
|
92 |
yield "".join(accumulated)
|
93 |
|
94 |
-
# Create interface with added voice input
|
95 |
with gr.Blocks() as demo:
|
96 |
-
# Original chat interface
|
97 |
chat_interface = gr.ChatInterface(
|
98 |
stream_generator,
|
99 |
textbox=gr.Textbox(placeholder="Ask Mistral...", container=False),
|
@@ -106,12 +112,10 @@ with gr.Blocks() as demo:
|
|
106 |
cache_examples=False,
|
107 |
)
|
108 |
|
109 |
-
# Add voice input below examples
|
110 |
with gr.Row():
|
111 |
audio = gr.Audio(sources=["microphone"], type="numpy", label="Voice Input")
|
112 |
transcribe_btn = gr.Button("Send Transcription")
|
113 |
|
114 |
-
# Connect transcription to chat input
|
115 |
transcribe_btn.click(
|
116 |
transcribe,
|
117 |
inputs=audio,
|
@@ -119,4 +123,4 @@ with gr.Blocks() as demo:
|
|
119 |
)
|
120 |
|
121 |
if __name__ == "__main__":
|
122 |
-
demo.launch(share=True,
|
|
|
1 |
+
from huggingface_hub import snapshot_download
|
2 |
+
|
3 |
+
# Download models from Hugging Face to local folders
|
4 |
+
snapshot_download(
|
5 |
+
repo_id="OpenVINO/Mistral-7B-Instruct-v0.2-int4-ov",
|
6 |
+
local_dir="mistral-ov"
|
7 |
+
)
|
8 |
+
snapshot_download(
|
9 |
+
repo_id="OpenVINO/whisper-tiny-fp16-ov",
|
10 |
+
local_dir="whisper-ov-model"
|
11 |
+
)
|
12 |
+
|
13 |
import gradio as gr
|
14 |
import openvino_genai
|
15 |
import librosa
|
16 |
import numpy as np
|
17 |
+
from threading import Thread, Lock, Event
|
18 |
from scipy.ndimage import uniform_filter1d
|
19 |
from queue import Queue, Empty
|
20 |
|
|
|
21 |
# Initialize Mistral pipeline
|
22 |
mistral_pipe = openvino_genai.LLMPipeline("mistral-ov", device="CPU")
|
23 |
config = openvino_genai.GenerationConfig(
|
24 |
+
max_new_tokens=100,
|
25 |
+
num_beams=1,
|
26 |
+
do_sample=False,
|
27 |
+
temperature=0.0,
|
28 |
+
top_p=1.0,
|
29 |
top_k=50
|
30 |
)
|
31 |
pipe_lock = Lock()
|
|
|
65 |
return whisper_pipe.generate(processed)
|
66 |
|
67 |
def stream_generator(message, history):
|
|
|
68 |
response_queue = Queue()
|
69 |
completion_event = Event()
|
70 |
error_message = [None]
|
|
|
76 |
def generate():
|
77 |
try:
|
78 |
with pipe_lock:
|
|
|
79 |
mistral_pipe.generate(message, config, callback)
|
|
|
80 |
except Exception as e:
|
81 |
error_message[0] = str(e)
|
82 |
finally:
|
|
|
99 |
|
100 |
yield "".join(accumulated)
|
101 |
|
|
|
102 |
with gr.Blocks() as demo:
|
|
|
103 |
chat_interface = gr.ChatInterface(
|
104 |
stream_generator,
|
105 |
textbox=gr.Textbox(placeholder="Ask Mistral...", container=False),
|
|
|
112 |
cache_examples=False,
|
113 |
)
|
114 |
|
|
|
115 |
with gr.Row():
|
116 |
audio = gr.Audio(sources=["microphone"], type="numpy", label="Voice Input")
|
117 |
transcribe_btn = gr.Button("Send Transcription")
|
118 |
|
|
|
119 |
transcribe_btn.click(
|
120 |
transcribe,
|
121 |
inputs=audio,
|
|
|
123 |
)
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
+
demo.launch(share=True,debug=True)
|
requirements.txt
CHANGED
@@ -1,9 +1,6 @@
|
|
1 |
-
gradio
|
2 |
-
openvino-genai>=
|
3 |
librosa>=0.10.0
|
4 |
-
numpy>=1.
|
5 |
scipy>=1.10.0
|
6 |
-
huggingface_hub>=0.
|
7 |
-
soundfile>=0.12.0
|
8 |
-
torch>=2.2.0 # Required for some components
|
9 |
-
transformers>=4.38.0 # Needed for audio processing
|
|
|
1 |
+
gradio==4.26.0
|
2 |
+
openvino-genai>=1.0.0
|
3 |
librosa>=0.10.0
|
4 |
+
numpy>=1.24.0
|
5 |
scipy>=1.10.0
|
6 |
+
huggingface_hub>=0.21.4
|
|
|
|
|
|