AIencoder commited on
Commit
6431de1
·
verified ·
1 Parent(s): 97c05be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,11 +1,12 @@
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
- # UPDATED: Pointing to the working bartowski GGUF repo
9
  MODELS = {
10
  "Qwen2.5-Coder 1.5B (Fastest)": "qwen2.5-coder:1.5b",
11
  "Qwen2.5-Coder 3B (Fast)": "qwen2.5-coder:3b",
@@ -24,12 +25,19 @@ def check_ollama():
24
  except:
25
  return False
26
 
27
- # NEW FUNCTION: Auto-download the model if missing
28
  def ensure_model(model_name):
29
- if not check_ollama():
30
- print("❌ Ollama not running, skipping model download.")
31
- return
32
 
 
 
 
 
 
 
 
 
 
33
  print(f"🔎 Checking for model: {model_name}")
34
  try:
35
  # Check if model is already loaded
@@ -39,7 +47,7 @@ def ensure_model(model_name):
39
  return
40
 
41
  # If not, pull it
42
- print(f"📥 Downloading {model_name}... (This may take a few minutes)")
43
  with requests.post(f"{OLLAMA_URL}/api/pull", json={"name": model_name}, stream=True) as r:
44
  for line in r.iter_lines():
45
  pass
 
1
  import gradio as gr
2
  import requests
3
  import json
4
+ import time
5
  from faster_whisper import WhisperModel
6
 
7
  OLLAMA_URL = "http://localhost:11434"
8
 
9
+ # Pointing to the working bartowski GGUF repo
10
  MODELS = {
11
  "Qwen2.5-Coder 1.5B (Fastest)": "qwen2.5-coder:1.5b",
12
  "Qwen2.5-Coder 3B (Fast)": "qwen2.5-coder:3b",
 
25
  except:
26
  return False
27
 
28
+ # NEW FUNCTION: Robust startup that waits for Ollama
29
  def ensure_model(model_name):
30
+ print(f"⏳ Waiting for Ollama to start...")
 
 
31
 
32
+ # Wait up to 30 seconds for Ollama to be ready
33
+ retries = 0
34
+ while not check_ollama():
35
+ time.sleep(2)
36
+ retries += 1
37
+ if retries > 15:
38
+ print("❌ Ollama failed to start in time.")
39
+ return
40
+
41
  print(f"🔎 Checking for model: {model_name}")
42
  try:
43
  # Check if model is already loaded
 
47
  return
48
 
49
  # If not, pull it
50
+ print(f"📥 Downloading {model_name}... (This WILL take time for 30B)")
51
  with requests.post(f"{OLLAMA_URL}/api/pull", json={"name": model_name}, stream=True) as r:
52
  for line in r.iter_lines():
53
  pass