Felguk commited on
Commit
95ad2c5
·
verified ·
1 Parent(s): 9c2c656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -1,21 +1,33 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the sentiment analysis model
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
 
 
7
  def analyze_sentiment(text):
8
  result = sentiment_pipeline(text)[0]
9
  return f"Label: {result['label']}, Confidence: {result['score']:.4f}"
10
 
11
- # Define the Gradio interface
 
 
 
 
 
 
 
 
 
12
  iface = gr.Interface(
13
  fn=analyze_sentiment,
14
- inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
15
  outputs="text",
16
- title="Sentiment Analysis",
17
- description="Enter a sentence to analyze its sentiment."
 
 
18
  )
19
 
20
- # Launch the interface
21
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Загружаем модель для анализа тональности
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
+ # Функция для анализа тональности текста
8
  def analyze_sentiment(text):
9
  result = sentiment_pipeline(text)[0]
10
  return f"Label: {result['label']}, Confidence: {result['score']:.4f}"
11
 
12
+ # Примеры текстов для анализа
13
+ examples = [
14
+ "I love programming, it's so much fun!",
15
+ "This movie was terrible, I hated it.",
16
+ "The weather is nice today.",
17
+ "I feel so frustrated with this project.",
18
+ "Gradio is an amazing tool for building ML demos!"
19
+ ]
20
+
21
+ # Создаем интерфейс Gradio
22
  iface = gr.Interface(
23
  fn=analyze_sentiment,
24
+ inputs=gr.Textbox(lines=2, placeholder="Введите текст здесь..."),
25
  outputs="text",
26
+ title="Анализ тональности текста",
27
+ description="Введите текст, чтобы определить его тональность.",
28
+ examples=examples, # Добавляем примеры
29
+ examples_per_page=5 # Количество примеров на странице
30
  )
31
 
32
+ # Запускаем интерфейс
33
  iface.launch()