Spaces:
Sleeping
Sleeping
nikolis
commited on
Commit
·
b02aedd
1
Parent(s):
70b3393
basic recipe generation example
Browse files- app.py +17 -0
- requirements.txt +1 -1
app.py
CHANGED
@@ -2,6 +2,23 @@ from fastapi import FastAPI
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@app.get("/")
|
6 |
def greet_json():
|
7 |
return {"Hello": "World!"}
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
5 |
+
MODEL_NAME = "flax-community/t5-recipe-generation"
|
6 |
+
client = InferenceClient(model=MODEL_NAME, token=API_KEY)
|
7 |
+
|
8 |
+
@app.post("/generate-recipe/")
|
9 |
+
def generate_recipe(ingredients: str):
|
10 |
+
"""
|
11 |
+
Generate a recipe from ingredients.
|
12 |
+
:param ingredients: A comma-separated list of ingredients.
|
13 |
+
:return: AI-generated recipe text.
|
14 |
+
"""
|
15 |
+
prompt = f"recipe: {ingredients}"
|
16 |
+
|
17 |
+
# Query the Hugging Face Inference API
|
18 |
+
response = client.text_generation(prompt, max_new_tokens=100)
|
19 |
+
|
20 |
+
return {"ingredients": ingredients, "recipe": response}
|
21 |
+
|
22 |
@app.get("/")
|
23 |
def greet_json():
|
24 |
return {"Hello": "World!"}
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
-
|
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
+
huggingface_hub
|