V6.0
Browse files
app.py
CHANGED
|
@@ -13,12 +13,29 @@ def load_model():
|
|
| 13 |
"""Load the AI4Bharat IndicConformer model"""
|
| 14 |
try:
|
| 15 |
print("Loading AI4Bharat IndicConformer model...")
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
print("✅ Model loaded successfully!")
|
| 18 |
return model
|
| 19 |
except Exception as e:
|
| 20 |
print(f"❌ Error loading model: {e}")
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Load the model
|
| 24 |
model = load_model()
|
|
@@ -137,6 +154,8 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 137 |
|
| 138 |
**मॉडल स्थिति (Model Status):** {model_status}
|
| 139 |
|
|
|
|
|
|
|
| 140 |
AI4Bharat के बहुभाषी मॉडल का उपयोग करके भाषण को टेक्स्ट में बदलें।
|
| 141 |
(Convert speech to text using AI4Bharat's multilingual model.)
|
| 142 |
|
|
@@ -190,6 +209,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 190 |
with gr.Row():
|
| 191 |
mic_submit_btn = gr.Button("🔄 ट्रांसक्राइब करें", variant="primary", size="lg")
|
| 192 |
clear_mic_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
|
|
|
|
| 193 |
|
| 194 |
with gr.Column(scale=1):
|
| 195 |
mic_output = gr.Textbox(
|
|
@@ -197,7 +217,8 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 197 |
placeholder="रिकॉर्डिंग के बाद आपका ट्रांस्क्रिप्शन यहाँ दिखाई देगा...",
|
| 198 |
lines=8,
|
| 199 |
max_lines=15,
|
| 200 |
-
interactive=
|
|
|
|
| 201 |
)
|
| 202 |
|
| 203 |
# Button actions for microphone tab
|
|
@@ -218,6 +239,13 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 218 |
lambda: (None, ""),
|
| 219 |
outputs=[microphone_input, mic_output]
|
| 220 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
with gr.Tab("📁 फ़ाइल अपलोड (File Upload)"):
|
| 223 |
gr.Markdown("### ट्रांस्क्रिप्शन के लिए एक ऑडियो फ़ाइल अपलोड करें")
|
|
@@ -235,6 +263,7 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 235 |
with gr.Row():
|
| 236 |
file_submit_btn = gr.Button("🔄 फ़ाइल ट्रांसक्राइब करें", variant="primary", size="lg")
|
| 237 |
clear_file_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
|
|
|
|
| 238 |
|
| 239 |
with gr.Column(scale=1):
|
| 240 |
file_output = gr.Textbox(
|
|
@@ -242,7 +271,8 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 242 |
placeholder="एक ऑडियो फ़ाइल अपलोड करें और ट्रांसक्राइब पर क्लिक करें...",
|
| 243 |
lines=8,
|
| 244 |
max_lines=15,
|
| 245 |
-
interactive=
|
|
|
|
| 246 |
)
|
| 247 |
|
| 248 |
# Button actions for file tab
|
|
@@ -256,6 +286,13 @@ with gr.Blocks(title="भारतीय भाषा स्पीच टू ट
|
|
| 256 |
lambda: (None, ""),
|
| 257 |
outputs=[file_input, file_output]
|
| 258 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
gr.Markdown(
|
| 261 |
f"""
|
|
|
|
| 13 |
"""Load the AI4Bharat IndicConformer model"""
|
| 14 |
try:
|
| 15 |
print("Loading AI4Bharat IndicConformer model...")
|
| 16 |
+
print("This may take 2-3 minutes for first time download...")
|
| 17 |
+
|
| 18 |
+
# Load model with low memory usage
|
| 19 |
+
model = AutoModel.from_pretrained(
|
| 20 |
+
model_name,
|
| 21 |
+
trust_remote_code=True,
|
| 22 |
+
torch_dtype=torch.float32,
|
| 23 |
+
low_cpu_mem_usage=True
|
| 24 |
+
)
|
| 25 |
print("✅ Model loaded successfully!")
|
| 26 |
return model
|
| 27 |
except Exception as e:
|
| 28 |
print(f"❌ Error loading model: {e}")
|
| 29 |
+
print("Trying alternative loading method...")
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
# Fallback: Load without low memory optimization
|
| 33 |
+
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
|
| 34 |
+
print("✅ Model loaded with fallback method!")
|
| 35 |
+
return model
|
| 36 |
+
except Exception as e2:
|
| 37 |
+
print(f"❌ All loading methods failed: {e2}")
|
| 38 |
+
return None
|
| 39 |
|
| 40 |
# Load the model
|
| 41 |
model = load_model()
|
|
|
|
| 154 |
|
| 155 |
**मॉडल स्थिति (Model Status):** {model_status}
|
| 156 |
|
| 157 |
+
{'⏳ **पहली बार लोड हो रहा है - कृपया 2-3 मिनट प्रतीक्षा करें (First time loading - please wait 2-3 minutes)**' if model is None else ''}
|
| 158 |
+
|
| 159 |
AI4Bharat के बहुभाषी मॉडल का उपयोग करके भाषण को टेक्स्ट में बदलें।
|
| 160 |
(Convert speech to text using AI4Bharat's multilingual model.)
|
| 161 |
|
|
|
|
| 209 |
with gr.Row():
|
| 210 |
mic_submit_btn = gr.Button("🔄 ट्रांसक्राइब करें", variant="primary", size="lg")
|
| 211 |
clear_mic_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
|
| 212 |
+
copy_mic_btn = gr.Button("📋 कॉपी करें", variant="secondary")
|
| 213 |
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
mic_output = gr.Textbox(
|
|
|
|
| 217 |
placeholder="रिकॉर्डिंग के बाद आपका ट्रांस्क्रिप्शन यहाँ दिखाई देगा...",
|
| 218 |
lines=8,
|
| 219 |
max_lines=15,
|
| 220 |
+
interactive=True, # Enable text selection and copying
|
| 221 |
+
show_copy_button=True # Add copy button
|
| 222 |
)
|
| 223 |
|
| 224 |
# Button actions for microphone tab
|
|
|
|
| 239 |
lambda: (None, ""),
|
| 240 |
outputs=[microphone_input, mic_output]
|
| 241 |
)
|
| 242 |
+
|
| 243 |
+
# Copy functionality for microphone tab
|
| 244 |
+
copy_mic_btn.click(
|
| 245 |
+
lambda x: x, # Return the same text to enable copying
|
| 246 |
+
inputs=mic_output,
|
| 247 |
+
outputs=mic_output
|
| 248 |
+
)
|
| 249 |
|
| 250 |
with gr.Tab("📁 फ़ाइल अपलोड (File Upload)"):
|
| 251 |
gr.Markdown("### ट्रांस्क्रिप्शन के लिए एक ऑडियो फ़ाइल अपलोड करें")
|
|
|
|
| 263 |
with gr.Row():
|
| 264 |
file_submit_btn = gr.Button("🔄 फ़ाइल ट्रांसक्राइब करें", variant="primary", size="lg")
|
| 265 |
clear_file_btn = gr.Button("🗑️ साफ़ करें", variant="secondary")
|
| 266 |
+
copy_file_btn = gr.Button("📋 कॉपी करें", variant="secondary")
|
| 267 |
|
| 268 |
with gr.Column(scale=1):
|
| 269 |
file_output = gr.Textbox(
|
|
|
|
| 271 |
placeholder="एक ऑडियो फ़ाइल अपलोड करें और ट्रांसक्राइब पर क्लिक करें...",
|
| 272 |
lines=8,
|
| 273 |
max_lines=15,
|
| 274 |
+
interactive=True, # Enable text selection and copying
|
| 275 |
+
show_copy_button=True # Add copy button
|
| 276 |
)
|
| 277 |
|
| 278 |
# Button actions for file tab
|
|
|
|
| 286 |
lambda: (None, ""),
|
| 287 |
outputs=[file_input, file_output]
|
| 288 |
)
|
| 289 |
+
|
| 290 |
+
# Copy functionality for file tab
|
| 291 |
+
copy_file_btn.click(
|
| 292 |
+
lambda x: x, # Return the same text to enable copying
|
| 293 |
+
inputs=file_output,
|
| 294 |
+
outputs=file_output
|
| 295 |
+
)
|
| 296 |
|
| 297 |
gr.Markdown(
|
| 298 |
f"""
|