Spaces:
Running
Running
File size: 724 Bytes
70b3393 1e8865c b30fc07 70b3393 b02aedd ce04927 b02aedd 70b3393 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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!"}
|