asad231 commited on
Commit
4b0a429
Β·
verified Β·
1 Parent(s): 48e1bb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -665,37 +665,38 @@
665
 
666
 
667
  import gradio as gr
668
- import torch
669
- from TTS.api import TTS # βœ… Correct import
670
-
671
- # βœ… XTTS config safe for PyTorch 2.6
672
- import TTS.tts.configs.xtts_config
673
- import TTS.tts.models.xtts
674
-
675
- torch.serialization.add_safe_globals([
676
- TTS.tts.configs.xtts_config.XttsConfig,
677
- TTS.tts.models.xtts.XttsAudioConfig
678
- ])
679
-
680
- # βœ… Load XTTS v2 model
681
- tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
682
-
683
- # βœ… Simple example function
684
- def generate_voice(text):
685
- tts.tts_to_file(
686
- text=text,
687
- file_path="voice.wav",
688
- language="en" # change to "ar" for Arabic
689
- )
690
- return "voice.wav"
691
-
692
- # βœ… Gradio interface
693
  gr.Interface(
694
- fn=generate_voice,
695
- inputs=gr.Textbox(label="Enter text to speak"),
696
- outputs=gr.Audio(label="Generated Audio"),
697
- title="AI Voice (XTTS v2)",
698
- description="Enter text and get AI voice using XTTS v2 model"
 
 
 
699
  ).launch()
700
 
701
 
 
665
 
666
 
667
  import gradio as gr
668
+ import requests
669
+
670
+ # βœ… Fetch Surah data
671
+ def get_surah(surah_name):
672
+ try:
673
+ url = f"https://api.alquran.cloud/v1/surah/{surah_name}/editions/quran-simple,en.asad"
674
+ response = requests.get(url)
675
+ response.raise_for_status()
676
+ data = response.json()
677
+
678
+ if 'data' in data and len(data['data']) == 2:
679
+ arabic = "\n\n".join(
680
+ [f"{i+1}. {a['text']}" for i, a in enumerate(data['data'][0]['ayahs'])]
681
+ )
682
+ translation = "\n\n".join(
683
+ [f"{i+1}. {t['text']}" for i, t in enumerate(data['data'][1]['ayahs'])]
684
+ )
685
+ return arabic, translation
686
+ return "Surah not found.", "Translation not found."
687
+ except Exception as e:
688
+ return f"API Error: {e}", ""
689
+
690
+ # βœ… Gradio UI
 
 
691
  gr.Interface(
692
+ fn=get_surah,
693
+ inputs=gr.Textbox(label="Enter Surah Name (e.g., Al-Fatiha, An-Nas)", placeholder="Al-Fatiha"),
694
+ outputs=[
695
+ gr.Textbox(label="πŸ“œ Arabic Text", lines=15),
696
+ gr.Textbox(label="🌐 English Translation", lines=15)
697
+ ],
698
+ title="πŸ“– Surah Viewer",
699
+ description="View full Surah from Quran with Arabic and English translation (No Audio)"
700
  ).launch()
701
 
702