alex-abb commited on
Commit
35f0746
1 Parent(s): cd8b63d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
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
- print("Réponse brute de l'API:", output) # Ajoutez cette ligne
 
27
 
28
  if isinstance(output, list) and len(output) > 0:
29
  response = output[0].get('generated_text', '').strip().lower()
30
- if 'positive1' in response:
31
- return 'positive'
32
- if 'negative1' in response:
33
- return 'negative'
34
- else:
35
- return "Erreur: Réponse inattendue"
 
 
36
  else:
37
- return "Erreur: Réponse inattendue de l'API"
 
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,