Spaces:
Sleeping
Sleeping
new version
Browse files- .gitattributes +2 -0
- app.py +31 -18
- bot.png +3 -0
- requirements.txt +18 -15
- user.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
bot.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
user.png filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import time
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
-
import openvino_genai
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
from threading import Lock, Event
|
| 7 |
import os
|
|
@@ -20,6 +20,11 @@ import textwrap
|
|
| 20 |
from queue import Queue, Empty
|
| 21 |
from concurrent.futures import ThreadPoolExecutor
|
| 22 |
from typing import Generator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Google API configuration
|
| 25 |
GOOGLE_API_KEY = "AIzaSyAo-1iW5MEZbc53DlEldtnUnDaYuTHUDH4"
|
|
@@ -43,12 +48,15 @@ class UnifiedAISystem:
|
|
| 43 |
def initialize_models(self):
|
| 44 |
"""Initialize all required models"""
|
| 45 |
# Download models if not exists
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# CPU-specific configuration
|
| 54 |
cpu_features = cpuinfo.get_cpu_info()['flags']
|
|
@@ -59,16 +67,13 @@ class UnifiedAISystem:
|
|
| 59 |
config_properties["INFERENCE_PRECISION_HINT"] = "f32"
|
| 60 |
|
| 61 |
# Initialize Mistral model with updated configuration
|
| 62 |
-
self.mistral_pipe =
|
| 63 |
"mistral-ov",
|
| 64 |
device="CPU",
|
| 65 |
PERFORMANCE_HINT="THROUGHPUT",
|
| 66 |
**config_properties
|
| 67 |
)
|
| 68 |
|
| 69 |
-
# Initialize Whisper for audio processing
|
| 70 |
-
self.whisper_pipe = openvino_genai.WhisperPipeline("whisper-ov-model", device="CPU")
|
| 71 |
-
|
| 72 |
def load_data(self, file_path):
|
| 73 |
"""Load student data from file"""
|
| 74 |
try:
|
|
@@ -119,7 +124,7 @@ class UnifiedAISystem:
|
|
| 119 |
completion_event = Event()
|
| 120 |
error = [None] # Use list to capture exception from thread
|
| 121 |
|
| 122 |
-
optimized_config =
|
| 123 |
max_new_tokens=max_tokens,
|
| 124 |
temperature=0.3,
|
| 125 |
top_p=0.9,
|
|
@@ -129,7 +134,7 @@ class UnifiedAISystem:
|
|
| 129 |
|
| 130 |
def callback(tokens): # Accepts multiple tokens
|
| 131 |
response_queue.put("".join(tokens))
|
| 132 |
-
return
|
| 133 |
|
| 134 |
def generate():
|
| 135 |
try:
|
|
@@ -223,7 +228,7 @@ class UnifiedAISystem:
|
|
| 223 |
|
| 224 |
# Lazy initialize InternVL
|
| 225 |
if self.internvl_pipe is None:
|
| 226 |
-
self.internvl_pipe =
|
| 227 |
|
| 228 |
with self.pipe_lock:
|
| 229 |
self.internvl_pipe.start_chat()
|
|
@@ -282,7 +287,7 @@ class UnifiedAISystem:
|
|
| 282 |
return np.array([], dtype=np.float32)
|
| 283 |
|
| 284 |
def transcribe(self, audio):
|
| 285 |
-
"""Transcribe audio using Whisper model
|
| 286 |
if audio is None:
|
| 287 |
return ""
|
| 288 |
sr, data = audio
|
|
@@ -298,9 +303,17 @@ class UnifiedAISystem:
|
|
| 298 |
if len(processed) < 8000: # 0.5 seconds at 16kHz
|
| 299 |
return ""
|
| 300 |
|
| 301 |
-
#
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
except Exception as e:
|
| 305 |
print(f"Transcription error: {e}")
|
| 306 |
return "❌ Transcription failed - please try again"
|
|
|
|
| 1 |
import time
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
import openvino_genai as ov_genai
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
from threading import Lock, Event
|
| 7 |
import os
|
|
|
|
| 20 |
from queue import Queue, Empty
|
| 21 |
from concurrent.futures import ThreadPoolExecutor
|
| 22 |
from typing import Generator
|
| 23 |
+
import warnings
|
| 24 |
+
from transformers import pipeline # Added for Whisper
|
| 25 |
+
|
| 26 |
+
# Suppress specific OpenVINO deprecation warning
|
| 27 |
+
warnings.filterwarnings("ignore", category=DeprecationWarning, module="openvino.runtime")
|
| 28 |
|
| 29 |
# Google API configuration
|
| 30 |
GOOGLE_API_KEY = "AIzaSyAo-1iW5MEZbc53DlEldtnUnDaYuTHUDH4"
|
|
|
|
| 48 |
def initialize_models(self):
|
| 49 |
"""Initialize all required models"""
|
| 50 |
# Download models if not exists
|
| 51 |
+
model_paths = {
|
| 52 |
+
"mistral-ov": "OpenVINO/mistral-7b-instruct-v0.1-int8-ov",
|
| 53 |
+
"internvl-ov": "OpenVINO/InternVL2-1B-int8-ov"
|
| 54 |
+
# Removed distil-whisper download since we're using transformers version
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
for local_dir, repo_id in model_paths.items():
|
| 58 |
+
if not os.path.exists(local_dir):
|
| 59 |
+
snapshot_download(repo_id=repo_id, local_dir=local_dir)
|
| 60 |
|
| 61 |
# CPU-specific configuration
|
| 62 |
cpu_features = cpuinfo.get_cpu_info()['flags']
|
|
|
|
| 67 |
config_properties["INFERENCE_PRECISION_HINT"] = "f32"
|
| 68 |
|
| 69 |
# Initialize Mistral model with updated configuration
|
| 70 |
+
self.mistral_pipe = ov_genai.LLMPipeline(
|
| 71 |
"mistral-ov",
|
| 72 |
device="CPU",
|
| 73 |
PERFORMANCE_HINT="THROUGHPUT",
|
| 74 |
**config_properties
|
| 75 |
)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
def load_data(self, file_path):
|
| 78 |
"""Load student data from file"""
|
| 79 |
try:
|
|
|
|
| 124 |
completion_event = Event()
|
| 125 |
error = [None] # Use list to capture exception from thread
|
| 126 |
|
| 127 |
+
optimized_config = ov_genai.GenerationConfig(
|
| 128 |
max_new_tokens=max_tokens,
|
| 129 |
temperature=0.3,
|
| 130 |
top_p=0.9,
|
|
|
|
| 134 |
|
| 135 |
def callback(tokens): # Accepts multiple tokens
|
| 136 |
response_queue.put("".join(tokens))
|
| 137 |
+
return ov_genai.StreamingStatus.RUNNING
|
| 138 |
|
| 139 |
def generate():
|
| 140 |
try:
|
|
|
|
| 228 |
|
| 229 |
# Lazy initialize InternVL
|
| 230 |
if self.internvl_pipe is None:
|
| 231 |
+
self.internvl_pipe = ov_genai.VLMPipeline("internvl-ov", device="CPU")
|
| 232 |
|
| 233 |
with self.pipe_lock:
|
| 234 |
self.internvl_pipe.start_chat()
|
|
|
|
| 287 |
return np.array([], dtype=np.float32)
|
| 288 |
|
| 289 |
def transcribe(self, audio):
|
| 290 |
+
"""Transcribe audio using OpenAI Whisper-small model"""
|
| 291 |
if audio is None:
|
| 292 |
return ""
|
| 293 |
sr, data = audio
|
|
|
|
| 303 |
if len(processed) < 8000: # 0.5 seconds at 16kHz
|
| 304 |
return ""
|
| 305 |
|
| 306 |
+
# Lazy initialize Whisper - USING TRANSFORMERS PIPELINE
|
| 307 |
+
if self.whisper_pipe is None:
|
| 308 |
+
self.whisper_pipe = pipeline(
|
| 309 |
+
"automatic-speech-recognition",
|
| 310 |
+
model="openai/whisper-small",
|
| 311 |
+
device="cpu" # Use CPU for consistency
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
# Use transformers pipeline for transcription
|
| 315 |
+
result = self.whisper_pipe(processed, return_timestamps=False)
|
| 316 |
+
return result["text"]
|
| 317 |
except Exception as e:
|
| 318 |
print(f"Transcription error: {e}")
|
| 319 |
return "❌ Transcription failed - please try again"
|
bot.png
ADDED
|
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
-
gradio==4.
|
| 2 |
-
openvino-genai
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.32.0
|
| 2 |
+
openvino-genai==0.4.0
|
| 3 |
+
huggingface_hub==0.23.2
|
| 4 |
+
pandas==2.2.2
|
| 5 |
+
numpy==1.26.4
|
| 6 |
+
requests==2.32.3
|
| 7 |
+
Pillow==10.3.0
|
| 8 |
+
openvino==2024.1.0
|
| 9 |
+
librosa==0.10.2.post1
|
| 10 |
+
google-api-python-client==2.132.0
|
| 11 |
+
PyPDF2==3.0.1
|
| 12 |
+
python-docx==1.1.2
|
| 13 |
+
transformers==4.41.2
|
| 14 |
+
torch==2.3.0
|
| 15 |
+
torchaudio==2.3.0
|
| 16 |
+
ffmpeg-python==0.2.0
|
| 17 |
+
soundfile==0.12.1
|
| 18 |
+
py-cpuinfo==9.0.0
|
user.png
ADDED
|
Git LFS Details
|