Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_path = "./trained_model" # Current directory where model files are located
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 8 |
+
|
| 9 |
+
# Define the function to generate a recipe
|
| 10 |
+
def generate_recipe(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(
|
| 13 |
+
**inputs,
|
| 14 |
+
max_length=200,
|
| 15 |
+
temperature=0.8,
|
| 16 |
+
top_k=50,
|
| 17 |
+
top_p=0.95,
|
| 18 |
+
num_return_sequences=1
|
| 19 |
+
)
|
| 20 |
+
recipe = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
+
return recipe
|
| 22 |
+
|
| 23 |
+
# Create the Gradio interface
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=generate_recipe,
|
| 26 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a recipe prompt (e.g., 'Chocolate cake recipe')", label="Recipe Prompt"),
|
| 27 |
+
outputs=gr.Textbox(label="Generated Recipe"),
|
| 28 |
+
title="Recipe Generator",
|
| 29 |
+
description="Enter a recipe idea or prompt, and let the AI generate a creative recipe for you!"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch the app
|
| 33 |
+
interface.launch()
|