Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Charger le
|
5 |
-
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
# Interface Gradio
|
14 |
with gr.Blocks() as demo:
|
15 |
-
gr.Markdown("#
|
16 |
-
|
17 |
-
with gr.Row():
|
18 |
-
prompt_input = gr.Textbox(label="Texte d'entrée (prompt)", placeholder="Saisissez votre texte ici")
|
19 |
-
max_length_input = gr.Slider(label="Longueur maximale", minimum=10, maximum=100, value=50)
|
20 |
-
num_sequences_input = gr.Slider(label="Nombre de textes générés", minimum=1, maximum=5, value=3)
|
21 |
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
inputs=[prompt_input, max_length_input, num_sequences_input],
|
28 |
-
outputs=output_text
|
29 |
-
)
|
30 |
|
31 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# Charger le tokenizer et le modèle pour la reconnaissance d'entités nommées (NER)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("sp01/ner_automotive")
|
7 |
+
model = AutoModelForTokenClassification.from_pretrained("sp01/ner_automotive")
|
8 |
|
9 |
+
# Créer un pipeline pour la NER
|
10 |
+
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# Fonction pour traiter l'entrée
|
13 |
+
def extract_entities(text):
|
14 |
+
entities = ner_pipeline(text)
|
15 |
+
return "\n".join([f"Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']}" for entity in entities])
|
16 |
|
17 |
# Interface Gradio
|
18 |
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown("# Extraction d'entités automobiles")
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Composants de l'interface
|
22 |
+
text_input = gr.Textbox(label="Entrez votre texte", placeholder="Ex: Tesla Model S est une voiture électrique.")
|
23 |
+
output_text = gr.Textbox(label="Entités extraites", lines=5)
|
24 |
|
25 |
+
# Lier le bouton à la fonction
|
26 |
+
text_input.submit(extract_entities, inputs=text_input, outputs=output_text)
|
|
|
|
|
|
|
27 |
|
28 |
demo.launch()
|