Spaces:
Sleeping
Sleeping
Pushing corrections for image loading
Browse files- main.py +3 -8
- utils/audio_utils.py +0 -2
main.py
CHANGED
@@ -6,6 +6,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
6 |
from fastapi.responses import JSONResponse
|
7 |
from pydantic import AnyHttpUrl, BaseModel, UrlConstraints
|
8 |
from contextlib import asynccontextmanager
|
|
|
9 |
|
10 |
from config import get_settings
|
11 |
import uvicorn
|
@@ -93,7 +94,7 @@ async def generate_topic(
|
|
93 |
status_code=status.HTTP_400_BAD_REQUEST,
|
94 |
detail="Image file must be ended with .jpg, .png, .jpeg"
|
95 |
)
|
96 |
-
img_file_object = img.file
|
97 |
elif img_url:
|
98 |
img_file_object = app.state.url_utils.load_image(img_url)
|
99 |
|
@@ -106,13 +107,7 @@ async def generate_topic(
|
|
106 |
)
|
107 |
except Exception as e:
|
108 |
logger.error(f"Error in generate_topic: {str(e)}")
|
109 |
-
raise HTTPException(
|
110 |
-
|
111 |
-
@app.post("/audioverse", response_model=AudioResponse)
|
112 |
-
async def generate_audio(text: str):
|
113 |
-
try:
|
114 |
-
audio_bytes = app.state.audio_utils.speak(text)
|
115 |
-
audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
|
116 |
return AudioResponse(audio_base64=audio_base64)
|
117 |
except Exception as e:
|
118 |
logger.error(f"Error in generate_audio: {str(e)}")
|
|
|
6 |
from fastapi.responses import JSONResponse
|
7 |
from pydantic import AnyHttpUrl, BaseModel, UrlConstraints
|
8 |
from contextlib import asynccontextmanager
|
9 |
+
from PIL import Image
|
10 |
|
11 |
from config import get_settings
|
12 |
import uvicorn
|
|
|
94 |
status_code=status.HTTP_400_BAD_REQUEST,
|
95 |
detail="Image file must be ended with .jpg, .png, .jpeg"
|
96 |
)
|
97 |
+
img_file_object = Image.open(img.file)
|
98 |
elif img_url:
|
99 |
img_file_object = app.state.url_utils.load_image(img_url)
|
100 |
|
|
|
107 |
)
|
108 |
except Exception as e:
|
109 |
logger.error(f"Error in generate_topic: {str(e)}")
|
110 |
+
raise HTTPException(staed64encode(audio_bytes).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
return AudioResponse(audio_base64=audio_base64)
|
112 |
except Exception as e:
|
113 |
logger.error(f"Error in generate_audio: {str(e)}")
|
utils/audio_utils.py
CHANGED
@@ -6,8 +6,6 @@ load_dotenv()
|
|
6 |
|
7 |
openai_key = os.getenv("OPENAI")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
class AudioUtils:
|
12 |
def __init__(self):
|
13 |
self.client = OpenAI(api_key=openai_key)
|
|
|
6 |
|
7 |
openai_key = os.getenv("OPENAI")
|
8 |
|
|
|
|
|
9 |
class AudioUtils:
|
10 |
def __init__(self):
|
11 |
self.client = OpenAI(api_key=openai_key)
|