Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
model_id = "ranggafermata/Fermata-v1.2-light" # replace with your actual repo
|
| 6 |
+
|
| 7 |
+
# Load model and tokenizer
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, attn_implementation="eager")
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
model_id,
|
| 11 |
+
device_map="auto",
|
| 12 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 13 |
+
attn_implementation="eager"
|
| 14 |
+
)
|
| 15 |
+
model.eval()
|
| 16 |
+
|
| 17 |
+
# Generation function
|
| 18 |
+
def chat(prompt, max_new_tokens=256, temperature=0.8, top_p=0.95):
|
| 19 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
outputs = model.generate(
|
| 22 |
+
**inputs,
|
| 23 |
+
max_new_tokens=max_new_tokens,
|
| 24 |
+
temperature=temperature,
|
| 25 |
+
top_p=top_p,
|
| 26 |
+
do_sample=True,
|
| 27 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 28 |
+
)
|
| 29 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
+
|
| 31 |
+
# Gradio interface
|
| 32 |
+
gr.Interface(
|
| 33 |
+
fn=chat,
|
| 34 |
+
inputs=[
|
| 35 |
+
gr.Textbox(lines=4, label="Prompt"),
|
| 36 |
+
gr.Slider(64, 1024, value=256, step=64, label="Max New Tokens"),
|
| 37 |
+
gr.Slider(0.1, 1.5, value=0.8, step=0.1, label="Temperature"),
|
| 38 |
+
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
|
| 39 |
+
],
|
| 40 |
+
outputs=gr.Textbox(label="Response"),
|
| 41 |
+
title="Fermata Assistant (Gemma 3 - 1B - IT)",
|
| 42 |
+
description="A smart assistant built on Gemma 3B with personality from the Fermata project."
|
| 43 |
+
).launch()
|