Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
| 4 |
+
|
| 5 |
+
# Load the model and processor
|
| 6 |
+
model_id = "google/functiongemma-270m-it"
|
| 7 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 9 |
+
|
| 10 |
+
def generate_tool_call(user_prompt):
|
| 11 |
+
# This model is designed for function calling/tool use
|
| 12 |
+
# It requires a specific prompt format (see model card for details)
|
| 13 |
+
inputs = processor(text=user_prompt, return_tensors="pt").to(model.device)
|
| 14 |
+
output = model.generate(**inputs, max_new_tokens=128)
|
| 15 |
+
return processor.decode(output[0], skip_special_tokens=True)
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=generate_tool_call,
|
| 19 |
+
inputs="text",
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="FunctionGemma 270M Demo",
|
| 22 |
+
description="A lightweight 270M model specialized in function calling."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|