from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse from transformers import pipeline import gradio as gr #app = FastAPI() pipe_flan = pipeline("text-generation", model="gpt2") #@app.get("/infer_gpt2") def gpt2(input): output = pipe_flan(input, max_length=130, num_return_sequences=1) return {"output": output[0]["generated_text"]} # return {"output": output[0]["generated_text"]} #app.mount("/", StaticFiles(directory="static", html=True), name="static") #@app.get("/") #def index() -> FileResponse: # return FileResponse(path="/app/static/index.html", media_type="text/html") demo = gr.Interface( fn=gpt2, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs=gr.outputs.Textbox(label="Generated Text") ) demo.launch()