File size: 1,099 Bytes
0454af4
26f3394
0454af4
26f3394
0454af4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26f3394
 
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
28
29
30
31
32
33
34
35
36
37
38
import torch
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

MODEL_NAME = "Manvtith/FoodExtract-gemma-3-270m-fine-tune-v1"

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
    MODEL_NAME,
    torch_dtype=torch.float16,
    device_map="auto"
)

def extract_food(text):
    prompt = f"Extract all food and drink items from this sentence:\n{text}\nAnswer:"
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=128,
            temperature=0.2,
            do_sample=False
        )

    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return result.split("Answer:")[-1].strip()

demo = gr.Interface(
    fn=extract_food,
    inputs=gr.Textbox(lines=3, placeholder="Type a sentence with food..."),
    outputs="text",
    title="Food & Drink Extractor (Gemma SLM)",
    description="Fine-tuned Gemma-3-270M to extract food and beverage items from text."
)

demo.launch()