Tiktok-Talent-Info/endpoints/text.py

43 lines
1.4 KiB
Python
Raw Permalink Normal View History

2025-01-26 20:42:56 +08:00
import asyncio
2025-01-23 21:50:55 +08:00
from fastapi import Form
from fastapi.responses import JSONResponse
from asyncio import to_thread
from pipeline_setup import pipe
2025-03-22 20:54:10 +08:00
# api
async def text_query(question: str = Form(...)):
"""
API endpoint to process text input with the user's query.
"""
try:
print("starting text querying...")
response = await to_thread(pipe, question)
return JSONResponse({"query": question, "response": response.text})
except Exception as e:
return JSONResponse({"query": question, "error": str(e)})
# gradio
2025-01-23 21:50:55 +08:00
# async def text_query(question: str = Form(...)):
# """
# API endpoint to process text input with the user's query.
# """
# try:
2025-03-22 20:54:10 +08:00
# print("Processing in text.py...")
# response = await to_thread(pipe, question)
# return {"query": question, "response": response.text}
2025-01-23 21:50:55 +08:00
# except Exception as e:
2025-03-22 20:54:10 +08:00
# return {"query": question, "error": str(e)}
2025-02-08 18:52:07 +08:00
2025-03-22 20:54:10 +08:00
# celery
# def text_query(question: str = Form(...)):
# """
# API endpoint to process text input with the user's query.
# """
# print("Testing....")
# try:
# print("Processing in text.py...")
# response = pipe(question) # Call pipe synchronously
# return {"query": question, "response": response.text}
# except Exception as e:
# return {"query": question, "error": str(e)}