import gradio as gr from transformers import pipeline # Загружаем модель для анализа тональности sentiment_pipeline = pipeline("sentiment-analysis") # Функция для анализа тональности текста def analyze_sentiment(text): result = sentiment_pipeline(text)[0] return f"Label: {result['label']}, Confidence: {result['score']:.4f}" # Примеры текстов для анализа examples = [ "I love programming, it's so much fun!", "This movie was terrible, I hated it.", "The weather is nice today.", "I feel so frustrated with this project.", "Gradio is an amazing tool for building ML demos!" ] # Создаем интерфейс Gradio iface = gr.Interface( fn=analyze_sentiment, inputs=gr.Textbox(lines=2, placeholder="Введите текст здесь..."), outputs="text", title="Анализ тональности текста", description="Введите текст, чтобы определить его тональность.", examples=examples, # Добавляем примеры examples_per_page=5 # Количество примеров на странице ) # Запускаем интерфейс iface.launch()