#text generation genai app (text to text) from fastapi import FastAPI from transformers import pipeline # we used pipeline so we can call any llm models that are present in hugging face # creaye fastapi app instnace app = FastAPI() # initiliaze text generation pipeline # Use a pipeline as a high-level helper pipe = pipeline("text2text-generation", model="google/flan-t5-small") # create @app.get("/") def home(): return {"message": "Welcome to the Text Generation App"} # generate fucntion to handle some get request /generate @app.get("/generate") def generate(text: str): #whatever the text we give it will post to my pipeline # use the pipeline to generate the text from given input text "(text:str)" try: output = pipe(text) return {"output": output[0].get("generated_text", "No output generated")} except Exception as e: return {"error": str(e)} # return {"output": output[0]['generated_text']} # output is given in the form of key anf rom the output we will getting the response in the form of list and over there