Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,39 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
import requests
|
|
|
4 |
import spaces
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
api_token = os.environ.get("HF_API_TOKEN")
|
8 |
|
9 |
-
|
|
|
10 |
headers = {"Authorization": f"Bearer {api_token}"}
|
11 |
-
@spaces.GPU
|
12 |
|
13 |
-
|
14 |
-
# Envoi de la requête
|
15 |
|
16 |
def query(payload):
|
17 |
response = requests.post(API_URL, headers=headers, json=payload)
|
18 |
return response.json()
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
outputs="text",
|
31 |
-
title="
|
32 |
-
description="Entrez un
|
33 |
)
|
34 |
|
35 |
# Lancer l'interface
|
36 |
-
interface.launch()
|
37 |
-
|
38 |
iface.launch()
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import gradio as gr
|
3 |
import spaces
|
4 |
+
import os
|
5 |
+
|
6 |
|
7 |
+
api_token = os.environ.get("TOKEN")
|
|
|
8 |
|
9 |
+
|
10 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-llama-3-8B-Instruct"
|
11 |
headers = {"Authorization": f"Bearer {api_token}"}
|
|
|
12 |
|
13 |
+
@spaces.GPU
|
|
|
14 |
|
15 |
def query(payload):
|
16 |
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
return response.json()
|
18 |
+
|
19 |
+
def detect_sentiment(message):
|
20 |
+
prompt = f"Détecte le sentiment de ce message. Réponds par 'positif' ou 'négatif' :\nMessage : \"{message}\""
|
21 |
+
response = query({"inputs": prompt})
|
22 |
+
sentiment = response[0]['generated_text'].strip().lower()
|
23 |
+
return sentiment
|
24 |
+
|
25 |
+
def sentiment_analysis_interface(message):
|
26 |
+
sentiment = detect_sentiment(message)
|
27 |
+
return sentiment
|
28 |
+
|
29 |
+
# Créer l'interface Gradio
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=sentiment_analysis_interface,
|
32 |
+
inputs="text",
|
33 |
outputs="text",
|
34 |
+
title="Détection de Sentiment",
|
35 |
+
description="Entrez un message pour détecter si le sentiment est positif ou négatif.",
|
36 |
)
|
37 |
|
38 |
# Lancer l'interface
|
|
|
|
|
39 |
iface.launch()
|