prav2705 commited on
Commit
affb0ad
·
1 Parent(s): 152e159

Fix ASR 404 error by using relative paths and bumping version for cache busting

Browse files
frontend/app.js CHANGED
@@ -4,7 +4,9 @@ const API_BASE = APP_CONFIG.API_BASE_URL || "https://api.corpus.swecha.org/api/v
4
  const HF_API_BASE = APP_CONFIG.HF_API_BASE_URL || "https://api-inference.huggingface.co/models";
5
  const HF_ASR_MODEL = APP_CONFIG.HF_ASR_MODEL || "viswamaicoe/swecha-gonthuka-asr";
6
  const HF_TOKEN = APP_CONFIG.HF_TOKEN || "";
7
- const LOCAL_ASR_BASE = APP_CONFIG.LOCAL_ASR_BASE_URL || "http://localhost:8000";
 
 
8
  const CORPUS_ASR_ENDPOINT = APP_CONFIG.CORPUS_ASR_ENDPOINT || "";
9
 
10
  // Auth elements
 
4
  const HF_API_BASE = APP_CONFIG.HF_API_BASE_URL || "https://api-inference.huggingface.co/models";
5
  const HF_ASR_MODEL = APP_CONFIG.HF_ASR_MODEL || "viswamaicoe/swecha-gonthuka-asr";
6
  const HF_TOKEN = APP_CONFIG.HF_TOKEN || "";
7
+ const LOCAL_ASR_BASE = (APP_CONFIG.LOCAL_ASR_BASE_URL !== undefined && APP_CONFIG.LOCAL_ASR_BASE_URL !== null && APP_CONFIG.LOCAL_ASR_BASE_URL !== "")
8
+ ? APP_CONFIG.LOCAL_ASR_BASE_URL
9
+ : "";
10
  const CORPUS_ASR_ENDPOINT = APP_CONFIG.CORPUS_ASR_ENDPOINT || "";
11
 
12
  // Auth elements
frontend/config.js CHANGED
@@ -9,6 +9,6 @@ window.APP_CONFIG = {
9
  HF_API_BASE_URL: "https://router.huggingface.co/hf-inference/models",
10
  HF_ASR_MODEL: "viswamaicoe/swecha-gonthuka-asr",
11
  HF_TOKEN: "",
12
- LOCAL_ASR_BASE_URL: "",
13
  };
14
 
 
9
  HF_API_BASE_URL: "https://router.huggingface.co/hf-inference/models",
10
  HF_ASR_MODEL: "viswamaicoe/swecha-gonthuka-asr",
11
  HF_TOKEN: "",
12
+ LOCAL_ASR_BASE_URL: "", // Set to empty for relative paths (e.g. in Hugging Face)
13
  };
14
 
frontend/index.html CHANGED
@@ -63,7 +63,7 @@
63
  </div>
64
 
65
  <script src="config.js"></script>
66
- <script src="app.js?v=6"></script>
67
  </body>
68
 
69
  </html>
 
63
  </div>
64
 
65
  <script src="config.js"></script>
66
+ <script src="app.js?v=7"></script>
67
  </body>
68
 
69
  </html>
packages.txt DELETED
@@ -1 +0,0 @@
1
- ffmpeg
 
 
requirements.txt DELETED
@@ -1,10 +0,0 @@
1
- streamlit==1.42.0
2
- fastapi==0.116.1
3
- uvicorn[standard]==0.35.0
4
- python-multipart==0.0.20
5
- transformers==4.48.3
6
- torch==2.5.1
7
- requests==2.32.4
8
- python-dotenv==1.1.1
9
- librosa==0.10.2
10
- soundfile==0.13.1
 
 
 
 
 
 
 
 
 
 
 
streamlit_app.py DELETED
@@ -1,132 +0,0 @@
1
- import os
2
- import tempfile
3
- import subprocess
4
- import re
5
- from functools import lru_cache
6
- from typing import Any
7
-
8
- import streamlit as st
9
- from transformers import pipeline
10
- import requests
11
-
12
- # Page Config
13
- st.set_page_config(
14
- page_title="Swecha Telugu Audio Tracker",
15
- page_icon="🎙️",
16
- layout="centered"
17
- )
18
-
19
- # Constants & Env
20
- MODEL_ID = os.getenv("MODEL_ID", "viswamaicoe/swecha-gonthuka-asr")
21
- ASR_DEVICE = os.getenv("ASR_DEVICE", "cpu").lower()
22
- SWECHA_API_BASE = os.getenv("SWECHA_API_BASE", "https://api.corpus.swecha.org")
23
- SWECHA_UPLOAD_PATH = os.getenv("SWECHA_UPLOAD_PATH", "/api/v1/content")
24
- SWECHA_AUTH_TOKEN = os.getenv("SWECHA_AUTH_TOKEN", "")
25
-
26
- # --- Logic from backend/main.py ---
27
-
28
- @lru_cache(maxsize=1)
29
- def get_asr_pipeline():
30
- device = 0 if ASR_DEVICE == "cuda" else -1
31
- return pipeline(
32
- task="automatic-speech-recognition",
33
- model=MODEL_ID,
34
- device=device,
35
- chunk_length_s=30,
36
- batch_size=8,
37
- )
38
-
39
- def clean_noisy_telugu(text: str) -> str:
40
- if not text:
41
- return ""
42
- cleaned = re.sub(r'్{2,}', '్', text)
43
- cleaned = re.sub(r'\s+', ' ', cleaned).strip()
44
- return cleaned
45
-
46
- def transcribe_audio(raw_bytes: bytes, suffix: str) -> str:
47
- asr = get_asr_pipeline()
48
-
49
- with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as input_file:
50
- input_file.write(raw_bytes)
51
- input_path = input_file.name
52
-
53
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as output_file:
54
- output_path = output_file.name
55
-
56
- try:
57
- ffmpeg_command = [
58
- "ffmpeg", "-y", "-i", input_path,
59
- "-acodec", "pcm_s16le", "-ac", "1", "-ar", "16000",
60
- output_path,
61
- ]
62
- subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
63
-
64
- result = asr(output_path, generate_kwargs={"task": "transcribe", "language": "telugu"})
65
-
66
- text = ""
67
- if isinstance(result, dict) and "text" in result:
68
- text = clean_noisy_telugu(result["text"])
69
- elif isinstance(result, str):
70
- text = clean_noisy_telugu(result)
71
- return text
72
-
73
- finally:
74
- for path in (input_path, output_path):
75
- if os.path.exists(path):
76
- os.remove(path)
77
-
78
- def push_to_swecha(audio_bytes, filename, transcript, title, description):
79
- if not SWECHA_AUTH_TOKEN:
80
- return {"error": "SWECHA_AUTH_TOKEN is not configured"}
81
-
82
- url = f"{SWECHA_API_BASE.rstrip('/')}/{SWECHA_UPLOAD_PATH.lstrip('/')}"
83
- headers = {"Authorization": f"Bearer {SWECHA_AUTH_TOKEN}"}
84
- files = {"audio": (filename, audio_bytes, "audio/webm")}
85
- data = {"title": title, "description": description, "transcript": transcript}
86
-
87
- resp = requests.post(url, headers=headers, files=files, data=data, timeout=60)
88
- return resp.json() if resp.ok else {"error": resp.text}
89
-
90
- # --- Streamlit UI ---
91
-
92
- st.title("🎙️ Swecha Telugu Audio Tracker")
93
- st.markdown("Convert Telugu audio to text and store it in the Swecha Corpus.")
94
-
95
- tab1, tab2 = st.tabs(["Upload/Record", "Settings"])
96
-
97
- with tab2:
98
- st.header("Configuration")
99
- model_id = st.text_input("ASR Model ID", MODEL_ID)
100
- auth_token = st.text_input("Swecha Auth Token", SWECHA_AUTH_TOKEN, type="password")
101
- if st.button("Save Settings"):
102
- os.environ["MODEL_ID"] = model_id
103
- os.environ["SWECHA_AUTH_TOKEN"] = auth_token
104
- st.success("Settings updated for this session!")
105
-
106
- with tab1:
107
- audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "webm", "m4a"])
108
-
109
- # Simple Record placeholder since custom components like streamlit-mic-recorder
110
- # might need specific installation and configuration.
111
- st.info("You can also record audio if you have 'streamlit-mic-recorder' installed. For now, please upload a file.")
112
-
113
- if audio_file:
114
- st.audio(audio_file)
115
-
116
- with st.expander("Metadata (Optional for storage)"):
117
- title = st.text_input("Title", value=audio_file.name)
118
- desc = st.text_area("Description")
119
-
120
- if st.button("Transcribe", type="primary"):
121
- with st.spinner("Transcribing Telugu..."):
122
- try:
123
- text = transcribe_audio(audio_file.read(), os.path.splitext(audio_file.name)[1])
124
- st.subheader("Transcription:")
125
- st.write(text)
126
-
127
- if text and SWECHA_AUTH_TOKEN:
128
- if st.button("Push to Swecha Corpus"):
129
- res = push_to_swecha(audio_file.getvalue(), audio_file.name, text, title, desc)
130
- st.json(res)
131
- except Exception as e:
132
- st.error(f"Error: {e}")