Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,33 +10,30 @@ API_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased-f
|
|
10 |
headers = {"Authorization": f"Bearer {api_token}"}
|
11 |
@spaces.GPU
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
try:
|
16 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
-
response.raise_for_status() # Lève une exception pour les codes d'erreur HTTP
|
18 |
-
result = response.json()
|
19 |
-
|
20 |
-
if isinstance(result, list) and len(result) > 0 and isinstance(result[0], list):
|
21 |
-
sentiment_scores = result[0]
|
22 |
-
sentiment = "heureux" if sentiment_scores[1] > sentiment_scores[0] else "malheureux"
|
23 |
-
return sentiment
|
24 |
-
else:
|
25 |
-
return "Erreur: Format de réponse inattendu"
|
26 |
-
except requests.RequestException as e:
|
27 |
-
return f"Erreur de requête: {str(e)}"
|
28 |
-
except Exception as e:
|
29 |
-
return f"Erreur inattendue: {str(e)}"
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
)
|
41 |
|
|
|
|
|
|
|
42 |
iface.launch()
|
|
|
10 |
headers = {"Authorization": f"Bearer {api_token}"}
|
11 |
@spaces.GPU
|
12 |
|
13 |
+
# Texte à analyser
|
14 |
+
input_text = "Can you please let us know more details about your "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Envoi de la requête
|
17 |
+
output = query({
|
18 |
+
"inputs": input_text,
|
19 |
+
})
|
20 |
|
21 |
+
# Analyse de la réponse
|
22 |
+
label = output[0]['label']
|
23 |
+
if label == 'POSITIVE':
|
24 |
+
return ('Positif')
|
25 |
+
else:
|
26 |
+
return ('Négatif')
|
27 |
+
|
28 |
+
interface = gr.Interface(
|
29 |
+
fn=analyze_sentiment,
|
30 |
+
inputs="text",
|
31 |
+
outputs="text",
|
32 |
+
title="Analyse de Sentiment",
|
33 |
+
description="Entrez un texte pour savoir s'il est positif ou négatif."
|
34 |
)
|
35 |
|
36 |
+
# Lancer l'interface
|
37 |
+
interface.launch()
|
38 |
+
|
39 |
iface.launch()
|