Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
tokeniser = AutoTokenizer.from_pretrained("rbawden/CCASS-semi-auto-titrages-base")
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("rbawden/CCASS-semi-auto-titrages-base")
|
6 |
+
|
7 |
+
|
8 |
+
def generate_titre(matiere_and_titrage_prefix):
|
9 |
+
inputs = tokeniser(matiere_and_titrage_prefix, return_tensors="pt")
|
10 |
+
outputs = model.generate(inputs["input_ids"])
|
11 |
+
res = tokeniser.batch_decode(
|
12 |
+
outputs, skip_special_tokens=True, clean_up_tokenisation_spaces=True
|
13 |
+
)
|
14 |
+
if not (
|
15 |
+
confirm := gr.inputs.Confirm(
|
16 |
+
label=f"Le modèle prédit que le titre est {res}. Est-ce le cas ?",
|
17 |
+
default=False,
|
18 |
+
).value
|
19 |
+
):
|
20 |
+
return {"FAIL"}
|
21 |
+
pred_titre += f"<t> {res} <t>"
|
22 |
+
inputs = tokeniser(matiere_and_titrage_prefix, return_tensors="pt")
|
23 |
+
outputs = model.generate(inputs["input_ids"])
|
24 |
+
res = tokeniser.batch_decode(
|
25 |
+
outputs, skip_special_tokens=True, clean_up_tokenisation_spaces=True
|
26 |
+
)
|
27 |
+
return {"next_prediction": res}
|
28 |
+
|
29 |
+
|
30 |
+
input_matter = gr.inputs.Textbox(label="Matière")
|
31 |
+
input_sommaire = gr.inputs.Textbox(label="Sommaire")
|
32 |
+
output_text = gr.outputs.Textbox(label="Next Prediction")
|
33 |
+
pred_titre = ""
|
34 |
+
matiere_and_titrage_prefix = f"{input_matter} {pred_titre} {input_sommaire}"
|
35 |
+
|
36 |
+
|
37 |
+
gr.Interface(
|
38 |
+
fn=generate_titre, inputs=matiere_and_titrage_prefix, outputs=output_text
|
39 |
+
).launch()
|