MariaKaiser commited on
Commit
6b26e57
·
verified ·
1 Parent(s): ab25d78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -119,6 +119,41 @@ app = FastAPI(title="EGTTS Arabic TTS API")
119
  def root():
120
  return {"message": "Welcome! Visit /docs for Swagger UI."}
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  ########## creating a dummy audio file
124
  import torchaudio
 
119
  def root():
120
  return {"message": "Welcome! Visit /docs for Swagger UI."}
121
 
122
+ #-----------------------------------------------------------
123
+
124
+ #__________ func to get file from supabase__________________
125
+
126
+ import httpx
127
+
128
+ async def download_file_from_url(url: str) -> bytes:
129
+ async with httpx.AsyncClient() as client:
130
+ response = await client.get(url)
131
+
132
+ if response.status_code != 200:
133
+ raise RuntimeError(f"Failed to fetch file: {response.text}")
134
+
135
+ return response.content
136
+
137
+ #-----------------------------------------------------------
138
+
139
+ #___________________Test end point to test supabase fetch
140
+
141
+ from fastapi import Query
142
+ from fastapi.responses import Response
143
+
144
+ @app.get("/test-download/")
145
+ async def test_download(url: str = Query(...)):
146
+ try:
147
+ file_bytes = await download_file_from_url(url)
148
+
149
+ return Response(
150
+ content=file_bytes,
151
+ media_type="audio/wav" # change if needed
152
+ )
153
+
154
+ except Exception as e:
155
+ return {"error": str(e)}
156
+ #_________________________________________
157
 
158
  ########## creating a dummy audio file
159
  import torchaudio