Neel2601 commited on
Commit
8959703
·
verified ·
1 Parent(s): d0761c6

Upload api_complete.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. api_complete.py +4 -28
api_complete.py CHANGED
@@ -1647,22 +1647,6 @@ async def voice_chat(audio_file: UploadFile = File(...), language: str = Form("h
1647
  raise HTTPException(status_code=500, detail=str(e))
1648
 
1649
  @app.post("/text-to-speech")
1650
- async def text_to_speech(
1651
- text: str = Form(...),
1652
- language: str = Form("hi") # Default to Hindi
1653
- ):
1654
- """Convert text to speech using advanced multilingual TTS"""
1655
- try:
1656
- # Import our multilingual TTS
1657
- from multilingual_tts import multilingual_tts
1658
- from fastapi.responses import FileResponse
1659
-
1660
- )
1661
-
1662
- except Exception as e:
1663
- logger.error(f"Text-to-speech error: {e}")
1664
- raise HTTPException(status_code=500, detail=str(e))
1665
-
1666
  @app.post("/text-to-speech")
1667
  async def text_to_speech(
1668
  text: str = Form(...),
@@ -1696,18 +1680,10 @@ async def text_to_speech(
1696
  except Exception as e:
1697
  logger.error(f"TTS error: {e}")
1698
  raise HTTPException(status_code=500, detail=str(e))
1699
- """Convert text to speech using gTTS (Google Text-to-Speech)"""
1700
- try:
1701
- # Map common language codes to gTTS codes
1702
- lang_map = {
1703
- 'hi': 'hi', 'en': 'en', 'bn': 'bn', 'gu': 'gu',
1704
- 'kn': 'kn', 'ml': 'ml', 'mr': 'mr', 'ta': 'ta',
1705
- 'te': 'te', 'ur': 'ur'
1706
- }
1707
-
1708
- tts_lang = lang_map.get(language, 'hi')
1709
-
1710
- logger.info(f"🗣️ Generating TTS for: '{text[:50]}...' in {tts_lang}")
1711
 
1712
  # Generate audio in memory
1713
  from gtts import gTTS
 
1647
  raise HTTPException(status_code=500, detail=str(e))
1648
 
1649
  @app.post("/text-to-speech")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1650
  @app.post("/text-to-speech")
1651
  async def text_to_speech(
1652
  text: str = Form(...),
 
1680
  except Exception as e:
1681
  logger.error(f"TTS error: {e}")
1682
  raise HTTPException(status_code=500, detail=str(e))
1683
+
1684
+ if __name__ == "__main__":
1685
+ import uvicorn
1686
+ uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
1687
 
1688
  # Generate audio in memory
1689
  from gtts import gTTS