Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,15 +11,23 @@ def analyze_sentiment(text):
|
|
11 |
payload = {
|
12 |
"inputs": f"Analyze the sentiment of the following text and respond with either 'heureux' or 'malheureux': {text}"
|
13 |
}
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def gradio_interface(input_text):
|
21 |
-
|
22 |
-
return sentiment
|
23 |
|
24 |
iface = gr.Interface(
|
25 |
fn=gradio_interface,
|
@@ -29,4 +37,4 @@ iface = gr.Interface(
|
|
29 |
description="Entrez un texte pour déterminer si le sentiment est 'heureux' ou 'malheureux'."
|
30 |
)
|
31 |
|
32 |
-
iface.launch()
|
|
|
11 |
payload = {
|
12 |
"inputs": f"Analyze the sentiment of the following text and respond with either 'heureux' or 'malheureux': {text}"
|
13 |
}
|
14 |
+
try:
|
15 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
16 |
+
response.raise_for_status() # Vérifie si la requête a réussi
|
17 |
+
result = response.json()
|
18 |
+
|
19 |
+
if isinstance(result, list) and len(result) > 0 and 'generated_text' in result[0]:
|
20 |
+
sentiment = result[0]['generated_text'].strip().lower()
|
21 |
+
return "heureux" if "heureux" in sentiment else "malheureux"
|
22 |
+
else:
|
23 |
+
return "Erreur: Format de réponse inattendu"
|
24 |
+
except requests.exceptions.RequestException as e:
|
25 |
+
return f"Erreur de requête: {str(e)}"
|
26 |
+
except Exception as e:
|
27 |
+
return f"Erreur inattendue: {str(e)}"
|
28 |
|
29 |
def gradio_interface(input_text):
|
30 |
+
return analyze_sentiment(input_text)
|
|
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn=gradio_interface,
|
|
|
37 |
description="Entrez un texte pour déterminer si le sentiment est 'heureux' ou 'malheureux'."
|
38 |
)
|
39 |
|
40 |
+
iface.launch(share=True)
|