wmaousley commited on
Commit
a7ab6a0
·
verified ·
1 Parent(s): eb8c8fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -11
app.py CHANGED
@@ -1,15 +1,38 @@
1
  import gradio as gr
 
 
2
 
3
- def critique(text):
4
- return "MiniCrit demo is running.\n\nYou entered:\n" + (text or "")
5
-
6
- demo = gr.Interface(
7
- fn=critique,
8
- inputs=gr.Textbox(lines=4, label="Input"),
9
- outputs=gr.Textbox(lines=8, label="Output"),
10
- title="MiniCrit Demo",
11
- description="Minimal working demo. Full model loads after GPU grant."
12
  )
13
 
14
- if __name__ == "__main__":
15
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()