Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import uvicorn
|
|
| 8 |
import soundfile as sf
|
| 9 |
import imageio
|
| 10 |
from typing import Dict, Optional
|
|
|
|
| 11 |
|
| 12 |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
|
| 13 |
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
|
|
@@ -137,7 +138,7 @@ async def generate(request: GenerateRequest, model_resources: tuple = Depends(ge
|
|
| 137 |
new_continuation_id = continuation_id if continuation_id else os.urandom(16).hex()
|
| 138 |
active_generations[new_continuation_id] = {"model_name": model_name, "output": generated_text}
|
| 139 |
|
| 140 |
-
return JSONResponse({"text": generated_text, "continuation_id": new_continuation_id})
|
| 141 |
|
| 142 |
except HTTPException as http_err:
|
| 143 |
raise http_err
|
|
@@ -187,7 +188,7 @@ async def generate_image(request: GenerateRequest):
|
|
| 187 |
image = image_generator(request.input_text)[0]
|
| 188 |
new_continuation_id = os.urandom(16).hex()
|
| 189 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Image generated successfully"}
|
| 190 |
-
return JSONResponse({"url": "Image generated successfully", "continuation_id": new_continuation_id})
|
| 191 |
|
| 192 |
except HTTPException as http_err:
|
| 193 |
raise http_err
|
|
@@ -204,7 +205,7 @@ async def generate_text_to_speech(request: GenerateRequest):
|
|
| 204 |
output = tts_pipeline(request.input_text)
|
| 205 |
new_continuation_id = os.urandom(16).hex()
|
| 206 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Audio generated successfully"}
|
| 207 |
-
return JSONResponse({"url": "Audio generated successfully", "continuation_id": new_continuation_id})
|
| 208 |
|
| 209 |
except HTTPException as http_err:
|
| 210 |
raise http_err
|
|
@@ -221,7 +222,7 @@ async def generate_video(request: GenerateRequest):
|
|
| 221 |
output = video_pipeline(request.input_text)
|
| 222 |
new_continuation_id = os.urandom(16).hex()
|
| 223 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Video generated successfully"}
|
| 224 |
-
return JSONResponse({"url": "Video generated successfully", "continuation_id": new_continuation_id})
|
| 225 |
|
| 226 |
except HTTPException as http_err:
|
| 227 |
raise http_err
|
|
|
|
| 8 |
import soundfile as sf
|
| 9 |
import imageio
|
| 10 |
from typing import Dict, Optional
|
| 11 |
+
import torch # Import torch
|
| 12 |
|
| 13 |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
|
| 14 |
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
|
|
|
|
| 138 |
new_continuation_id = continuation_id if continuation_id else os.urandom(16).hex()
|
| 139 |
active_generations[new_continuation_id] = {"model_name": model_name, "output": generated_text}
|
| 140 |
|
| 141 |
+
return JSONResponse({"text": generated_text, "continuation_id": new_continuation_id, "model_name": model_name})
|
| 142 |
|
| 143 |
except HTTPException as http_err:
|
| 144 |
raise http_err
|
|
|
|
| 188 |
image = image_generator(request.input_text)[0]
|
| 189 |
new_continuation_id = os.urandom(16).hex()
|
| 190 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Image generated successfully"}
|
| 191 |
+
return JSONResponse({"url": "Image generated successfully", "continuation_id": new_continuation_id, "model_name": request.model_name})
|
| 192 |
|
| 193 |
except HTTPException as http_err:
|
| 194 |
raise http_err
|
|
|
|
| 205 |
output = tts_pipeline(request.input_text)
|
| 206 |
new_continuation_id = os.urandom(16).hex()
|
| 207 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Audio generated successfully"}
|
| 208 |
+
return JSONResponse({"url": "Audio generated successfully", "continuation_id": new_continuation_id, "model_name": request.model_name})
|
| 209 |
|
| 210 |
except HTTPException as http_err:
|
| 211 |
raise http_err
|
|
|
|
| 222 |
output = video_pipeline(request.input_text)
|
| 223 |
new_continuation_id = os.urandom(16).hex()
|
| 224 |
active_generations[new_continuation_id] = {"model_name": request.model_name, "output": "Video generated successfully"}
|
| 225 |
+
return JSONResponse({"url": "Video generated successfully", "continuation_id": new_continuation_id, "model_name": request.model_name})
|
| 226 |
|
| 227 |
except HTTPException as http_err:
|
| 228 |
raise http_err
|