Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, Query, Request | |
from fastapi.responses import JSONResponse, HTMLResponse | |
from transformers import pipeline | |
import subprocess | |
import httpx | |
from transformers import pipeline | |
app = FastAPI() | |
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small") | |
def t5(input): | |
output = pipe_flan(input) | |
return {"output": output[0]["generated_text"]} | |
async def streamlit_proxy(request: Request): | |
async with httpx.AsyncClient() as client: | |
streamlit_url = "http://localhost:8501/" | |
response = await client.get(streamlit_url) | |
return HTMLResponse(content=response.text, status_code=response.status_code) | |
async def startup_event(): | |
# Запуск Streamlit в отдельном процессе | |
subprocess.Popen(["streamlit", "run", "streamlit_app.py"]) |