Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import whisper
|
|
| 3 |
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
import warnings
|
|
|
|
| 6 |
warnings.filterwarnings("ignore")
|
| 7 |
|
| 8 |
|
|
@@ -15,11 +16,12 @@ generator = pipeline(
|
|
| 15 |
"text-generation",
|
| 16 |
model=model_name,
|
| 17 |
device_map="auto",
|
| 18 |
-
|
| 19 |
)
|
| 20 |
|
| 21 |
print("Models ready.")
|
| 22 |
|
|
|
|
| 23 |
def transcribe(audio_path: str) -> str:
|
| 24 |
"""Transcribe audio file to text using Whisper."""
|
| 25 |
if audio_path is None:
|
|
@@ -27,7 +29,7 @@ def transcribe(audio_path: str) -> str:
|
|
| 27 |
result = whisper_model.transcribe(audio_path)
|
| 28 |
return result["text"].strip()
|
| 29 |
|
| 30 |
-
|
| 31 |
def reflect(transcript: str) -> str:
|
| 32 |
"""Generate a journaling reflection using Qwen."""
|
| 33 |
if not transcript:
|
|
|
|
| 3 |
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
import warnings
|
| 6 |
+
import spaces
|
| 7 |
warnings.filterwarnings("ignore")
|
| 8 |
|
| 9 |
|
|
|
|
| 16 |
"text-generation",
|
| 17 |
model=model_name,
|
| 18 |
device_map="auto",
|
| 19 |
+
dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 20 |
)
|
| 21 |
|
| 22 |
print("Models ready.")
|
| 23 |
|
| 24 |
+
@spaces.GPU
|
| 25 |
def transcribe(audio_path: str) -> str:
|
| 26 |
"""Transcribe audio file to text using Whisper."""
|
| 27 |
if audio_path is None:
|
|
|
|
| 29 |
result = whisper_model.transcribe(audio_path)
|
| 30 |
return result["text"].strip()
|
| 31 |
|
| 32 |
+
@spaces.GPU
|
| 33 |
def reflect(transcript: str) -> str:
|
| 34 |
"""Generate a journaling reflection using Qwen."""
|
| 35 |
if not transcript:
|