Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import spaces | |
| API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct" | |
| headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} | |
| def analyze_sentiment(text): | |
| payload = { | |
| "inputs": f"Analyze the sentiment of the following text and respond with either 'heureux' or 'malheureux': {text}" | |
| } | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| result = response.json() | |
| sentiment = result[0]['generated_text'].strip().lower() | |
| return "heureux" if "heureux" in sentiment else "malheureux" | |
| def gradio_interface(input_text): | |
| sentiment = analyze_sentiment(input_text) | |
| return sentiment | |
| iface = gr.Interface( | |
| fn=gradio_interface, | |
| inputs=gr.Textbox(lines=3, placeholder="Entrez votre texte ici..."), | |
| outputs=gr.Label(num_top_classes=1), | |
| title="Analyseur de Sentiment", | |
| description="Entrez un texte pour déterminer si le sentiment est 'heureux' ou 'malheureux'." | |
| ) | |
| iface.launch() |