Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from transformers import pipeline
|
| 4 |
-
import spaces
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
@spaces.GPU
|
| 9 |
def analyze_sentiment(text):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return "\n".join(sentiments)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
description="Entrez un texte pour analyser son sentiment (positif, négatif, ou neutre). Le modèle utilisé est un modèle généraliste finement ajusté pour la classification des sentiments."
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 5 |
+
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 6 |
|
|
|
|
| 7 |
def analyze_sentiment(text):
|
| 8 |
+
payload = {
|
| 9 |
+
"inputs": f"Analyze the sentiment of the following text and respond with either 'heureux' or 'malheureux': {text}"
|
| 10 |
+
}
|
| 11 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 12 |
+
result = response.json()
|
| 13 |
+
|
| 14 |
+
sentiment = result[0]['generated_text'].strip().lower()
|
| 15 |
+
return "heureux" if "heureux" in sentiment else "malheureux"
|
|
|
|
| 16 |
|
| 17 |
+
def gradio_interface(input_text):
|
| 18 |
+
sentiment = analyze_sentiment(input_text)
|
| 19 |
+
return sentiment
|
| 20 |
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=gradio_interface,
|
| 23 |
+
inputs=gr.Textbox(lines=3, placeholder="Entrez votre texte ici..."),
|
| 24 |
+
outputs=gr.Label(num_top_classes=1),
|
| 25 |
+
title="Analyseur de Sentiment",
|
| 26 |
+
description="Entrez un texte pour déterminer si le sentiment est 'heureux' ou 'malheureux'."
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
+
iface.launch()
|
|
|
|
|
|