alex-abb commited on
Commit
d5b1d28
·
verified ·
1 Parent(s): cc11b4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -15,32 +15,37 @@ def query(payload):
15
 
16
 
17
  def analyze_sentiment(text):
18
- output = query({
19
  "inputs": f'''<|begin_of_text|>
20
  <|start_header_id|>system<|end_header_id|>
21
- you are a feeling analyser and you'll say only "positive" if i'm feeling positive and "negativ" if i'm feeling sad or bad <|eot_id|>
22
  <|start_header_id|>user<|end_header_id|>
23
  {text}
24
  <|eot_id|>
25
  <|start_header_id|>assistant<|end_header_id|>
26
-
27
- "parameters": {
28
- "max_new_tokens": 1,
29
- "return_full_text": False
30
- }
31
  '''
32
  })
33
 
34
  # Assurez-vous de gérer correctement la sortie de l'API
35
  if isinstance(output, list) and len(output) > 0:
36
  return output[0].get('generated_text', 'Erreur: Réponse inattendue')
 
 
 
 
 
 
37
  else:
38
- return "Erreur: Réponse inattendue de l'API"
 
 
 
 
39
 
40
  demo = gr.Interface(
41
- fn = analyze_sentiment,
42
  inputs=["text"],
43
- outputs=["text"],
44
  )
45
 
46
  demo.launch()
 
15
 
16
 
17
  def analyze_sentiment(text):
18
+ output = query({
19
  "inputs": f'''<|begin_of_text|>
20
  <|start_header_id|>system<|end_header_id|>
21
+ you are a feeling analyser and you'll say only "positive" if i'm feeling positive and "negativ" if i'm feeling sad <|eot_id|>
22
  <|start_header_id|>user<|end_header_id|>
23
  {text}
24
  <|eot_id|>
25
  <|start_header_id|>assistant<|end_header_id|>
 
 
 
 
 
26
  '''
27
  })
28
 
29
  # Assurez-vous de gérer correctement la sortie de l'API
30
  if isinstance(output, list) and len(output) > 0:
31
  return output[0].get('generated_text', 'Erreur: Réponse inattendue')
32
+ if isinstance(output, list) and len(output) > 0:
33
+ response = output[0].get('generated_text', '').strip().lower()
34
+ if 'positive' in response:
35
+ return 'positive'
36
+ elif 'negative' in response:
37
+ return 'negative'
38
  else:
39
+ return "Erreur: Réponse inattendue"
40
+
41
+
42
+
43
+
44
 
45
  demo = gr.Interface(
46
+ fn = query,
47
  inputs=["text"],
48
+ outputs=["text"]
49
  )
50
 
51
  demo.launch()