Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,25 +15,24 @@ def query(payload):
|
|
15 |
response = requests.post(API_URL, headers=headers, json=payload)
|
16 |
return response.json()
|
17 |
|
18 |
-
|
19 |
def analyze_sentiment(text):
|
20 |
-
prompt = f"
|
21 |
|
22 |
output = query({
|
23 |
"inputs": prompt,
|
24 |
})
|
25 |
|
26 |
if isinstance(output, list) and len(output) > 0:
|
27 |
-
response = output[0].get('generated_text', '')
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
return
|
32 |
else:
|
33 |
return "Sentiment non détecté"
|
34 |
else:
|
35 |
return "Erreur: Réponse inattendue de l'API"
|
36 |
-
|
37 |
demo = gr.Interface(
|
38 |
fn = analyze_sentiment,
|
39 |
inputs=["text"],
|
|
|
15 |
response = requests.post(API_URL, headers=headers, json=payload)
|
16 |
return response.json()
|
17 |
|
|
|
18 |
def analyze_sentiment(text):
|
19 |
+
prompt = f"Analyse le sentiment de ce texte et réponds uniquement par 'positif' ou 'négatif' sans aucune autre explication : {text}"
|
20 |
|
21 |
output = query({
|
22 |
"inputs": prompt,
|
23 |
})
|
24 |
|
25 |
if isinstance(output, list) and len(output) > 0:
|
26 |
+
response = output[0].get('generated_text', '').strip().lower()
|
27 |
+
if 'positif' in response:
|
28 |
+
return "positif"
|
29 |
+
elif 'négatif' in response:
|
30 |
+
return "négatif"
|
31 |
else:
|
32 |
return "Sentiment non détecté"
|
33 |
else:
|
34 |
return "Erreur: Réponse inattendue de l'API"
|
35 |
+
|
36 |
demo = gr.Interface(
|
37 |
fn = analyze_sentiment,
|
38 |
inputs=["text"],
|