AIencoder commited on
Commit
af6e169
·
verified ·
1 Parent(s): 76c9c5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import gradio as gr
2
  import requests
3
  import json
 
4
 
5
  OLLAMA_URL = "http://localhost:11434"
6
- HF_API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
7
 
8
  MODELS = {
9
  "Qwen2.5-Coder 1.5B (Fastest)": "qwen2.5-coder:1.5b",
@@ -11,6 +11,11 @@ MODELS = {
11
  "Qwen2.5-Coder 7B (Quality)": "qwen2.5-coder:7b",
12
  }
13
 
 
 
 
 
 
14
  def check_ollama():
15
  try:
16
  r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=5)
@@ -23,16 +28,9 @@ def transcribe_audio(audio):
23
  return ""
24
 
25
  try:
26
- with open(audio, "rb") as f:
27
- data = f.read()
28
-
29
- response = requests.post(HF_API_URL, data=data, timeout=60)
30
-
31
- if response.status_code == 200:
32
- result = response.json()
33
- return result.get("text", "")
34
- else:
35
- return f"[STT Error: {response.status_code}]"
36
  except Exception as e:
37
  return f"[STT Error: {e}]"
38
 
 
1
  import gradio as gr
2
  import requests
3
  import json
4
+ from faster_whisper import WhisperModel
5
 
6
  OLLAMA_URL = "http://localhost:11434"
 
7
 
8
  MODELS = {
9
  "Qwen2.5-Coder 1.5B (Fastest)": "qwen2.5-coder:1.5b",
 
11
  "Qwen2.5-Coder 7B (Quality)": "qwen2.5-coder:7b",
12
  }
13
 
14
+ # Load Whisper locally (tiny model = ~75MB RAM)
15
+ print("Loading Whisper...")
16
+ whisper_model = WhisperModel("tiny", device="cpu", compute_type="int8")
17
+ print("Whisper ready!")
18
+
19
  def check_ollama():
20
  try:
21
  r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=5)
 
28
  return ""
29
 
30
  try:
31
+ segments, _ = whisper_model.transcribe(audio)
32
+ text = " ".join([seg.text for seg in segments])
33
+ return text.strip()
 
 
 
 
 
 
 
34
  except Exception as e:
35
  return f"[STT Error: {e}]"
36