Spaces:
Runtime error
Runtime error
Commit
·
02c56e5
1
Parent(s):
88b138c
update avec ajout de detection de permettre
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
|
|
2 |
import json
|
3 |
import logging
|
4 |
import os
|
|
|
|
|
5 |
from typing import List, Tuple
|
6 |
from pydantic import BaseModel, Field
|
7 |
from langchain.output_parsers import PydanticOutputParser
|
@@ -11,6 +13,9 @@ from langchain.chat_models import ChatOpenAI
|
|
11 |
# Configure logging
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
|
|
|
|
|
|
14 |
# Pydantic models for style error detection
|
15 |
class StyleErrorDetection(BaseModel):
|
16 |
erroneous_expression: str = Field(..., description="L'expression ou la tournure incorrecte détectée")
|
@@ -70,25 +75,75 @@ def analyze_style_errors(text: str) -> dict:
|
|
70 |
logging.info("LLM chain completed.")
|
71 |
return result
|
72 |
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
input_text = st.text_area("Entrez votre texte ici :", height=200)
|
78 |
|
79 |
-
#
|
80 |
if st.button("Lancer l'analyse"):
|
81 |
if input_text:
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
else:
|
94 |
-
st.error("Veuillez entrer du texte pour lancer l'analyse.")
|
|
|
2 |
import json
|
3 |
import logging
|
4 |
import os
|
5 |
+
import spacy
|
6 |
+
|
7 |
from typing import List, Tuple
|
8 |
from pydantic import BaseModel, Field
|
9 |
from langchain.output_parsers import PydanticOutputParser
|
|
|
13 |
# Configure logging
|
14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
15 |
|
16 |
+
# Load the French spaCy model
|
17 |
+
nlp = spacy.load('fr_core_news_md')
|
18 |
+
|
19 |
# Pydantic models for style error detection
|
20 |
class StyleErrorDetection(BaseModel):
|
21 |
erroneous_expression: str = Field(..., description="L'expression ou la tournure incorrecte détectée")
|
|
|
75 |
logging.info("LLM chain completed.")
|
76 |
return result
|
77 |
|
78 |
+
# Function to detect forms of the verb "permettre" in a text
|
79 |
+
def detect_permettre_forms(text: str) -> list:
|
80 |
+
doc = nlp(text)
|
81 |
+
resultats = []
|
82 |
+
for i, token in enumerate(doc):
|
83 |
+
# Vérifier si le lemme est "permettre" et que le mot est un verbe (autre que "permis")
|
84 |
+
if token.lemma_ == "permettre" and token.pos_ == "VERB" and token.text.lower() != "permis":
|
85 |
+
resultats.append((token.text, token.idx))
|
86 |
+
# Traiter spécifiquement le mot "permis"
|
87 |
+
elif token.text.lower() == "permis":
|
88 |
+
est_verbe = False
|
89 |
+
# Vérifier si le mot précédent est un auxiliaire
|
90 |
+
if i > 0 and doc[i - 1].pos_ == "AUX":
|
91 |
+
est_verbe = True
|
92 |
+
# Vérifier si le mot suivant est "de" suivi d'un verbe à l'infinitif
|
93 |
+
elif i + 2 < len(doc) and doc[i + 1].text.lower() == "de" and doc[i + 2].pos_ == "VERB" and "Inf" in doc[i + 2].tag_:
|
94 |
+
est_verbe = True
|
95 |
+
# Vérifier si le mot précédent est un déterminant (le, la, un, une, etc.)
|
96 |
+
elif i > 0 and doc[i - 1].pos_ == "DET":
|
97 |
+
est_verbe = False
|
98 |
+
else:
|
99 |
+
# Autres cas, on suppose que c'est un nom
|
100 |
+
est_verbe = False
|
101 |
+
|
102 |
+
if est_verbe:
|
103 |
+
resultats.append((token.text, token.idx))
|
104 |
+
return resultats
|
105 |
+
|
106 |
+
# Interface Streamlit
|
107 |
+
st.title("Analyse du texte")
|
108 |
+
|
109 |
+
# Menu déroulant pour sélectionner l'analyse
|
110 |
+
option = st.selectbox(
|
111 |
+
"Choisissez l'analyse à effectuer :",
|
112 |
+
("Détection des fautes de style", "Détection du verbe 'permettre'")
|
113 |
+
)
|
114 |
+
|
115 |
+
# Champ de saisie du texte
|
116 |
input_text = st.text_area("Entrez votre texte ici :", height=200)
|
117 |
|
118 |
+
# Bouton d'analyse
|
119 |
if st.button("Lancer l'analyse"):
|
120 |
if input_text:
|
121 |
+
if option == "Détection des fautes de style":
|
122 |
+
try:
|
123 |
+
# Analyser le texte pour les fautes de style
|
124 |
+
result = analyze_style_errors(input_text)
|
125 |
+
|
126 |
+
# Afficher les résultats en JSON formaté
|
127 |
+
st.subheader("Résultats de l'analyse des fautes de style")
|
128 |
+
st.json(result, expanded=True)
|
129 |
+
|
130 |
+
except Exception as e:
|
131 |
+
logging.error(f"Error during analysis: {e}")
|
132 |
+
st.error(f"Une erreur s'est produite lors de l'analyse : {str(e)}")
|
133 |
+
elif option == "Détection du verbe 'permettre'":
|
134 |
+
try:
|
135 |
+
# Détecter les formes du verbe "permettre"
|
136 |
+
result = detect_permettre_forms(input_text)
|
137 |
+
|
138 |
+
# Afficher les résultats
|
139 |
+
st.subheader("Résultats de la détection du verbe 'permettre'")
|
140 |
+
if result:
|
141 |
+
for mot, index in result:
|
142 |
+
st.write(f"Mot : '{mot}' à l'index {index}")
|
143 |
+
else:
|
144 |
+
st.write("Aucune forme du verbe 'permettre' n'a été trouvée.")
|
145 |
+
except Exception as e:
|
146 |
+
logging.error(f"Error during detection: {e}")
|
147 |
+
st.error(f"Une erreur s'est produite lors de la détection : {str(e)}")
|
148 |
else:
|
149 |
+
st.error("Veuillez entrer du texte pour lancer l'analyse.")
|