Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
MODEL = "wmaousley/MiniCrit-1.5B" # replace with your model name
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 8 |
+
|
| 9 |
+
# use low memory 4-bit load if supported
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
+
MODEL,
|
| 12 |
+
torch_dtype=torch.float16,
|
| 13 |
+
device_map="auto"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
def critique(text):
|
| 17 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_new_tokens=256,
|
| 22 |
+
do_sample=False,
|
| 23 |
+
temperature=0.0
|
| 24 |
+
)
|
| 25 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 26 |
+
return result
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
with gr.Blocks(title="MiniCrit Demo") as demo:
|
| 30 |
+
gr.Markdown("# 🔍 MiniCrit Demo\nA lightweight adversarial critic model.")
|
| 31 |
+
|
| 32 |
+
inp = gr.Textbox(label="Input text", placeholder="Enter text for critique")
|
| 33 |
+
out = gr.Textbox(label="Model Output")
|
| 34 |
+
|
| 35 |
+
btn = gr.Button("Run Critique")
|
| 36 |
+
btn.click(critique, inp, out)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|