phani50101 commited on
Commit
c18e7fd
·
verified ·
1 Parent(s): 375c8fe

new version

Browse files
Files changed (5) hide show
  1. .gitattributes +2 -0
  2. app.py +31 -18
  3. bot.png +3 -0
  4. requirements.txt +18 -15
  5. 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
- if not os.path.exists("mistral-ov"):
47
- snapshot_download(repo_id="OpenVINO/mistral-7b-instruct-v0.1-int8-ov", local_dir="mistral-ov")
48
- if not os.path.exists("internvl-ov"):
49
- snapshot_download(repo_id="OpenVINO/InternVL2-1B-int8-ov", local_dir="internvl-ov")
50
- if not os.path.exists("whisper-ov-model"):
51
- snapshot_download(repo_id="OpenVINO/whisper-tiny-fp16-ov", local_dir="whisper-ov-model")
 
 
 
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 = openvino_genai.LLMPipeline(
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 = openvino_genai.GenerationConfig(
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 openvino_genai.StreamingStatus.RUNNING
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 = openvino_genai.VLMPipeline("internvl-ov", device="CPU")
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 with improved error handling"""
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
- # Use OpenVINO Whisper pipeline
302
- result = self.whisper_pipe.generate(processed)
303
- return result
 
 
 
 
 
 
 
 
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

  • SHA256: b0bc9d2daf2b3c25156dea69db12fa8186d5ffbfd5df57bfd3c5a75887f64939
  • Pointer size: 131 Bytes
  • Size of remote file: 185 kB
requirements.txt CHANGED
@@ -1,15 +1,18 @@
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
7
- google-api-python-client>=2.0.0
8
- pandas>=2.0.0
9
- requests>=2.31.0
10
- Pillow>=10.0.0
11
- py-cpuinfo>=9.0.0
12
- openvino>=2023.2.0
13
- PyPDF2>=3.0.0
14
- python-docx>=1.1.0
15
- soundfile>=0.12.0
 
 
 
 
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

  • SHA256: b0bc9d2daf2b3c25156dea69db12fa8186d5ffbfd5df57bfd3c5a75887f64939
  • Pointer size: 131 Bytes
  • Size of remote file: 185 kB