Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ api_token = os.environ.get("TOKEN")
|
|
6 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
7 |
headers = {"Authorization": f"Bearer {api_token}"}
|
8 |
|
|
|
|
|
9 |
def query(payload):
|
10 |
response = requests.post(API_URL, headers=headers, json=payload)
|
11 |
return response.json()
|
@@ -23,18 +25,22 @@ You are a feeling analyser and you'll say only "positive1" if I'm feeling positi
|
|
23 |
|
24 |
'''
|
25 |
})
|
26 |
-
|
|
|
27 |
|
28 |
if isinstance(output, list) and len(output) > 0:
|
29 |
response = output[0].get('generated_text', '').strip().lower()
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
else:
|
37 |
-
return "Erreur: Réponse
|
|
|
38 |
|
39 |
demo = gr.Interface(
|
40 |
fn=analyze_sentiment,
|
|
|
6 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
7 |
headers = {"Authorization": f"Bearer {api_token}"}
|
8 |
|
9 |
+
|
10 |
+
|
11 |
def query(payload):
|
12 |
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
return response.json()
|
|
|
25 |
|
26 |
'''
|
27 |
})
|
28 |
+
|
29 |
+
|
30 |
|
31 |
if isinstance(output, list) and len(output) > 0:
|
32 |
response = output[0].get('generated_text', '').strip().lower()
|
33 |
+
|
34 |
+
positive_count = response.count('positive')
|
35 |
+
negative_count = response.count('negative')
|
36 |
+
|
37 |
+
if positive_count >= 2:
|
38 |
+
return 'positive'
|
39 |
+
elif negative_count >= 2:
|
40 |
+
return 'negative'
|
41 |
else:
|
42 |
+
return f"Erreur: Réponse ambiguë - '{response}'"
|
43 |
+
|
44 |
|
45 |
demo = gr.Interface(
|
46 |
fn=analyze_sentiment,
|