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") @app.get("/infer_t5") def t5(input): output = pipe_flan(input) return {"output": output[0]["generated_text"]} @app.get("/", response_class=HTMLResponse) 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) @app.on_event("startup") async def startup_event(): # Запуск Streamlit в отдельном процессе subprocess.Popen(["streamlit", "run", "streamlit_app.py"])