File size: 1,277 Bytes
9c2c656
 
 
95ad2c5
9c2c656
 
95ad2c5
9c2c656
 
 
 
95ad2c5
 
 
 
 
 
 
 
 
 
9c2c656
 
95ad2c5
9c2c656
95ad2c5
 
 
 
9c2c656
 
95ad2c5
9c2c656
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()