Update the eradme
Browse files
app.py
CHANGED
|
@@ -10,11 +10,9 @@ if 'model' in sys.modules:
|
|
| 10 |
|
| 11 |
from model import miniGPT
|
| 12 |
|
| 13 |
-
# Device setup
|
| 14 |
DEVICE = "cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu")
|
| 15 |
print(f"Loading model on device: {DEVICE}")
|
| 16 |
|
| 17 |
-
# Load the trained model (with config inference from state_dict, like in model.ipynb)
|
| 18 |
SCRIPT_DIR = Path(__file__).parent
|
| 19 |
model_dir = SCRIPT_DIR / "trained_model_small"
|
| 20 |
|
|
@@ -27,7 +25,6 @@ if model_dir.exists():
|
|
| 27 |
for item in model_dir.iterdir():
|
| 28 |
print(f" - {item.name}")
|
| 29 |
try:
|
| 30 |
-
# Load using the fixed loader that handles config/weight mismatches
|
| 31 |
trainer = miniGPT.load(str(model_dir), map_location=DEVICE)
|
| 32 |
trainer = trainer.to(DEVICE)
|
| 33 |
print("β Model loaded successfully!")
|
|
@@ -47,7 +44,6 @@ else:
|
|
| 47 |
|
| 48 |
|
| 49 |
def generate_recipe(prompt, max_length=300, temperature=0.85, top_k=50, top_p=0.95):
|
| 50 |
-
"""Generate a recipe given a prompt."""
|
| 51 |
if trainer is None:
|
| 52 |
if error_message:
|
| 53 |
return f"β Error: Model not loaded.\n\nDetails: {error_message}"
|
|
@@ -65,16 +61,18 @@ def generate_recipe(prompt, max_length=300, temperature=0.85, top_k=50, top_p=0.
|
|
| 65 |
except Exception as e:
|
| 66 |
return f"β Error generating recipe: {str(e)}"
|
| 67 |
|
| 68 |
-
|
| 69 |
-
# Gradio interface
|
| 70 |
with gr.Blocks(title="Recipe Generator", theme=gr.themes.Soft()) as demo:
|
| 71 |
gr.Markdown(
|
| 72 |
"""
|
| 73 |
-
#
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
-
**Model Info:** ~
|
|
|
|
|
|
|
| 78 |
"""
|
| 79 |
)
|
| 80 |
|
|
@@ -87,7 +85,7 @@ with gr.Blocks(title="Recipe Generator", theme=gr.themes.Soft()) as demo:
|
|
| 87 |
value="Recipe for chocolate ",
|
| 88 |
)
|
| 89 |
with gr.Column():
|
| 90 |
-
generate_btn = gr.Button("
|
| 91 |
|
| 92 |
output = gr.Textbox(label="Generated Recipe", lines=12, max_lines=20)
|
| 93 |
|
|
@@ -109,7 +107,7 @@ with gr.Blocks(title="Recipe Generator", theme=gr.themes.Soft()) as demo:
|
|
| 109 |
outputs=output,
|
| 110 |
)
|
| 111 |
|
| 112 |
-
#
|
| 113 |
gr.Examples(
|
| 114 |
examples=[
|
| 115 |
["Recipe for chocolate ", 300, 0.85, 50, 0.95],
|
|
@@ -127,14 +125,14 @@ with gr.Blocks(title="Recipe Generator", theme=gr.themes.Soft()) as demo:
|
|
| 127 |
gr.Markdown(
|
| 128 |
"""
|
| 129 |
### How to use:
|
| 130 |
-
1. Enter a
|
| 131 |
-
2. Adjust
|
| 132 |
-
3. Click "
|
| 133 |
|
| 134 |
### Tips:
|
| 135 |
-
- **Temperature**: Higher values (1.0+) make the
|
| 136 |
- **Top-K**: Limits sampling to top K most likely tokens
|
| 137 |
-
- **Top-P**:
|
| 138 |
"""
|
| 139 |
)
|
| 140 |
|
|
|
|
| 10 |
|
| 11 |
from model import miniGPT
|
| 12 |
|
|
|
|
| 13 |
DEVICE = "cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu")
|
| 14 |
print(f"Loading model on device: {DEVICE}")
|
| 15 |
|
|
|
|
| 16 |
SCRIPT_DIR = Path(__file__).parent
|
| 17 |
model_dir = SCRIPT_DIR / "trained_model_small"
|
| 18 |
|
|
|
|
| 25 |
for item in model_dir.iterdir():
|
| 26 |
print(f" - {item.name}")
|
| 27 |
try:
|
|
|
|
| 28 |
trainer = miniGPT.load(str(model_dir), map_location=DEVICE)
|
| 29 |
trainer = trainer.to(DEVICE)
|
| 30 |
print("β Model loaded successfully!")
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def generate_recipe(prompt, max_length=300, temperature=0.85, top_k=50, top_p=0.95):
|
|
|
|
| 47 |
if trainer is None:
|
| 48 |
if error_message:
|
| 49 |
return f"β Error: Model not loaded.\n\nDetails: {error_message}"
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"β Error generating recipe: {str(e)}"
|
| 63 |
|
|
|
|
|
|
|
| 64 |
with gr.Blocks(title="Recipe Generator", theme=gr.themes.Soft()) as demo:
|
| 65 |
gr.Markdown(
|
| 66 |
"""
|
| 67 |
+
# Welcome eggs 1/4 cup - stupidcookgpt
|
| 68 |
+
|
| 69 |
+
Generate recipes using a fine-tuned miniGPT model trained on recipe data.
|
| 70 |
|
| 71 |
+
Verified to generate your next delicious meal in 20 seconds (unless it doesn't).
|
| 72 |
|
| 73 |
+
**Model Info:** ~124M parameters, trained on corbt/all-recipes.
|
| 74 |
+
|
| 75 |
+
*small print*: ppl this is a friggin demo not some gordon ramsay, pls use common sense and don't sue me if you eat its egg-chocolate-broccoli surprise.
|
| 76 |
"""
|
| 77 |
)
|
| 78 |
|
|
|
|
| 85 |
value="Recipe for chocolate ",
|
| 86 |
)
|
| 87 |
with gr.Column():
|
| 88 |
+
generate_btn = gr.Button("Tell the chef...", variant="primary", size="lg")
|
| 89 |
|
| 90 |
output = gr.Textbox(label="Generated Recipe", lines=12, max_lines=20)
|
| 91 |
|
|
|
|
| 107 |
outputs=output,
|
| 108 |
)
|
| 109 |
|
| 110 |
+
# example prompts
|
| 111 |
gr.Examples(
|
| 112 |
examples=[
|
| 113 |
["Recipe for chocolate ", 300, 0.85, 50, 0.95],
|
|
|
|
| 125 |
gr.Markdown(
|
| 126 |
"""
|
| 127 |
### How to use:
|
| 128 |
+
1. Enter a prompt 4 the chef
|
| 129 |
+
2. Adjust chef parameters if desired (make it gordon ramsay when Temp=2 or a chill cook with Temp=0.4)
|
| 130 |
+
3. Click "Tell the chef..." to create a new recipe
|
| 131 |
|
| 132 |
### Tips:
|
| 133 |
+
- **Temperature**: Higher values (1.0+) make the chef more creative but probably more sus.
|
| 134 |
- **Top-K**: Limits sampling to top K most likely tokens
|
| 135 |
+
- **Top-P**: Only considers tokens with cumulative probability <= P
|
| 136 |
"""
|
| 137 |
)
|
| 138 |
|