Spaces:
Running
Running
Daniel Lakens commited on
Commit ·
28e3cfc
1
Parent(s): 6cecf95
app and requirements
Browse files- app.py +36 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import AutoModel, AutoTokenizer
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Load model and tokenizer
|
| 7 |
+
repo_id = "rasoultilburg/SocioCausaNet"
|
| 8 |
+
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
| 10 |
+
|
| 11 |
+
# Prediction function
|
| 12 |
+
def predict(sentences, rel_mode="auto", rel_threshold=0.5, cause_decision="cls+span"):
|
| 13 |
+
results = model.predict(
|
| 14 |
+
sentences,
|
| 15 |
+
tokenizer=tokenizer,
|
| 16 |
+
rel_mode=rel_mode,
|
| 17 |
+
rel_threshold=rel_threshold,
|
| 18 |
+
cause_decision=cause_decision
|
| 19 |
+
)
|
| 20 |
+
return json.dumps(results, indent=2, ensure_ascii=False)
|
| 21 |
+
|
| 22 |
+
# Gradio interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Textbox(label="Sentences (comma-separated)", placeholder="Enter sentences"),
|
| 27 |
+
gr.Radio(["auto", "neural_only"], label="Relation Mode", value="auto"),
|
| 28 |
+
gr.Slider(0.0, 1.0, value=0.5, label="Relation Threshold"),
|
| 29 |
+
gr.Radio(["cls_only", "span_only", "cls+span"], label="Cause Decision", value="cls+span")
|
| 30 |
+
],
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="SocioCausaNet API",
|
| 33 |
+
description="Extract causal relations from text"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.30.0
|
| 2 |
+
torch
|
| 3 |
+
gradio
|