Spaces:
Sleeping
Sleeping
Update app.py
Browse filesUpdated to include both UI and Publicly callable API
app.py
CHANGED
@@ -1,24 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
3 |
|
4 |
-
# Load
|
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 |
-
|
|
|
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 |
-
|
13 |
-
return label
|
14 |
|
15 |
-
# Build
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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()
|