from fastapi import FastAPI from huggingface_hub import InferenceClient import os app = FastAPI() MODEL_NAME = "flax-community/t5-recipe-generation" client = InferenceClient(model=MODEL_NAME, token=os.getenv('API_KEY')) @app.post("/generate-recipe/") def generate_recipe(ingredients: str): """ Generate a recipe from ingredients. :param ingredients: A comma-separated list of ingredients. :return: AI-generated recipe text. """ prompt = f"recipe: {ingredients}" # Query the Hugging Face Inference API response = client.text_generation(prompt, max_new_tokens=100) return {"ingredients": ingredients, "recipe": response} @app.get("/") def greet_json(): return {"Hello": "World!"}