Spaces:
Sleeping
Sleeping
Hjgugugjhuhjggg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from fastapi import FastAPI, HTTPException, Depends
|
3 |
from fastapi.responses import JSONResponse
|
4 |
from pydantic import BaseModel, field_validator, ValidationError
|
5 |
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, GenerationConfig, StoppingCriteriaList, pipeline, StoppingCriteria
|
@@ -103,7 +103,7 @@ async def get_model_and_tokenizer(model_name: str):
|
|
103 |
raise HTTPException(status_code=500, detail=f"Error loading model: {e}")
|
104 |
|
105 |
@app.post("/generate")
|
106 |
-
async def generate(request: GenerateRequest, model_resources: tuple = Depends(get_model_and_tokenizer)):
|
107 |
model, tokenizer = model_resources
|
108 |
try:
|
109 |
model_name = request.model_name
|
@@ -192,7 +192,7 @@ async def load_pipeline_from_s3(task, model_name):
|
|
192 |
raise HTTPException(status_code=500, detail=f"Error loading {task} model from S3: {e}")
|
193 |
|
194 |
@app.post("/generate-image")
|
195 |
-
async def generate_image(request: GenerateRequest):
|
196 |
try:
|
197 |
if request.task_type != "text-to-image":
|
198 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|
@@ -212,7 +212,7 @@ async def generate_image(request: GenerateRequest):
|
|
212 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
213 |
|
214 |
@app.post("/generate-text-to-speech")
|
215 |
-
async def generate_text_to_speech(request: GenerateRequest):
|
216 |
try:
|
217 |
if request.task_type != "text-to-speech":
|
218 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|
@@ -232,7 +232,7 @@ async def generate_text_to_speech(request: GenerateRequest):
|
|
232 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
233 |
|
234 |
@app.post("/generate-video")
|
235 |
-
async def generate_video(request: GenerateRequest):
|
236 |
try:
|
237 |
if request.task_type != "text-to-video":
|
238 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|
|
|
1 |
import os
|
2 |
+
from fastapi import FastAPI, HTTPException, Depends, Body
|
3 |
from fastapi.responses import JSONResponse
|
4 |
from pydantic import BaseModel, field_validator, ValidationError
|
5 |
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, GenerationConfig, StoppingCriteriaList, pipeline, StoppingCriteria
|
|
|
103 |
raise HTTPException(status_code=500, detail=f"Error loading model: {e}")
|
104 |
|
105 |
@app.post("/generate")
|
106 |
+
async def generate(request: GenerateRequest = Body(...), model_resources: tuple = Depends(get_model_and_tokenizer)):
|
107 |
model, tokenizer = model_resources
|
108 |
try:
|
109 |
model_name = request.model_name
|
|
|
192 |
raise HTTPException(status_code=500, detail=f"Error loading {task} model from S3: {e}")
|
193 |
|
194 |
@app.post("/generate-image")
|
195 |
+
async def generate_image(request: GenerateRequest = Body(...)):
|
196 |
try:
|
197 |
if request.task_type != "text-to-image":
|
198 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|
|
|
212 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
213 |
|
214 |
@app.post("/generate-text-to-speech")
|
215 |
+
async def generate_text_to_speech(request: GenerateRequest = Body(...)):
|
216 |
try:
|
217 |
if request.task_type != "text-to-speech":
|
218 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|
|
|
232 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
233 |
|
234 |
@app.post("/generate-video")
|
235 |
+
async def generate_video(request: GenerateRequest = Body(...)):
|
236 |
try:
|
237 |
if request.task_type != "text-to-video":
|
238 |
raise HTTPException(status_code=400, detail="Invalid task_type for this endpoint.")
|