Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
+
import torch
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
|
| 5 |
+
MODEL_NAME = "Manvtith/FoodExtract-gemma-3-270m-fine-tune-v1"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
MODEL_NAME,
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def extract_food(text):
|
| 15 |
+
prompt = f"Extract all food and drink items from this sentence:\n{text}\nAnswer:"
|
| 16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 17 |
+
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_new_tokens=128,
|
| 22 |
+
temperature=0.2,
|
| 23 |
+
do_sample=False
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
return result.split("Answer:")[-1].strip()
|
| 28 |
+
|
| 29 |
+
demo = gr.Interface(
|
| 30 |
+
fn=extract_food,
|
| 31 |
+
inputs=gr.Textbox(lines=3, placeholder="Type a sentence with food..."),
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="Food & Drink Extractor (Gemma SLM)",
|
| 34 |
+
description="Fine-tuned Gemma-3-270M to extract food and beverage items from text."
|
| 35 |
+
)
|
| 36 |
|
|
|
|
| 37 |
demo.launch()
|