gcuomo commited on
Commit
21004c4
·
verified ·
1 Parent(s): 6be3fc1

Update app.py

Browse files

Updated to include both UI and Publicly callable API

Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -1,24 +1,31 @@
1
  import gradio as gr
2
  from transformers import T5ForConditionalGeneration, T5Tokenizer
3
 
4
- # Load your fine-tuned model
5
  model = T5ForConditionalGeneration.from_pretrained("gcuomo/open-source-ai-t5-liar-lens")
6
  tokenizer = T5Tokenizer.from_pretrained("gcuomo/open-source-ai-t5-liar-lens")
7
 
8
- def classify_statement(statement):
 
9
  prompt = f"summarize: {statement}"
10
  inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=128)
11
  output = model.generate(**inputs, max_new_tokens=8)
12
- label = tokenizer.decode(output[0], skip_special_tokens=True).strip().lower()
13
- return label
14
 
15
- # Build the UI
16
- demo = gr.Interface(
17
- fn=classify_statement,
18
- inputs=gr.Textbox(lines=2, label="Enter a short statement"),
19
- outputs=gr.Textbox(label="Predicted Label"),
20
- title="Open Source AI LIAR Lens",
21
- description="A T5 model fine-tuned on the LIAR dataset and Open Source AI examples. Try a claim and see how the model labels it (e.g. true, half-true, pants-fire)."
22
- )
23
 
 
 
 
 
 
 
 
 
24
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import T5ForConditionalGeneration, T5Tokenizer
3
 
4
+ # Load model and tokenizer
5
  model = T5ForConditionalGeneration.from_pretrained("gcuomo/open-source-ai-t5-liar-lens")
6
  tokenizer = T5Tokenizer.from_pretrained("gcuomo/open-source-ai-t5-liar-lens")
7
 
8
+ # Shared prediction function
9
+ def classify(statement):
10
  prompt = f"summarize: {statement}"
11
  inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=128)
12
  output = model.generate(**inputs, max_new_tokens=8)
13
+ return tokenizer.decode(output[0], skip_special_tokens=True).strip().lower()
 
14
 
15
+ # Build UI with Blocks
16
+ with gr.Blocks() as demo:
17
+ gr.Markdown("## 🤥 Open Source AI – LIAR Lens")
18
+
19
+ with gr.Row():
20
+ inp = gr.Textbox(label="Enter a statement", lines=2, placeholder="e.g. The Eiffel Tower is in Berlin.")
21
+ out = gr.Textbox(label="Predicted label")
 
22
 
23
+ btn = gr.Button("Classify")
24
+ btn.click(fn=classify, inputs=inp, outputs=out)
25
+
26
+ # Register for remote access via gradio_client
27
+ demo.predict = classify # 👈 this makes remote .predict(...) possible
28
+
29
+ # Enable queueing and launch
30
+ demo.queue()
31
  demo.launch()