Felguk commited on
Commit
b2d3653
·
verified ·
1 Parent(s): cad6abc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций и автодополнения кода
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
  summarization_pipeline = pipeline("summarization")
7
  image_captioning_pipeline = pipeline("image-to-text")
@@ -9,6 +9,7 @@ qa_pipeline = pipeline("question-answering")
9
  translation_pipeline = pipeline("translation_en_to_ru", model="Helsinki-NLP/opus-mt-en-ru")
10
  emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
11
  code_completion_pipeline = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
 
12
 
13
  # Функция для анализа тональности текста
14
  def analyze_sentiment(text):
@@ -45,6 +46,11 @@ def complete_code(code):
45
  result = code_completion_pipeline(code, max_length=50, num_return_sequences=1)
46
  return result[0]['generated_text']
47
 
 
 
 
 
 
48
  # Примеры текстов для анализа тональности
49
  sentiment_examples = [
50
  "I love programming, it's so much fun!",
@@ -98,6 +104,13 @@ code_examples = [
98
  "for i in range(10):"
99
  ]
100
 
 
 
 
 
 
 
 
101
  # Создаем интерфейс Gradio с вкладками
102
  with gr.Blocks() as demo:
103
  with gr.Tab("Sentiment Analysis"):
@@ -173,6 +186,16 @@ with gr.Blocks() as demo:
173
  examples=code_examples,
174
  examples_per_page=2
175
  )
 
 
 
 
 
 
 
 
 
 
176
 
177
  # Запускаем интерфейс
178
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения кода и определения фейковых новостей
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
  summarization_pipeline = pipeline("summarization")
7
  image_captioning_pipeline = pipeline("image-to-text")
 
9
  translation_pipeline = pipeline("translation_en_to_ru", model="Helsinki-NLP/opus-mt-en-ru")
10
  emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
11
  code_completion_pipeline = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
12
+ fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
13
 
14
  # Функция для анализа тональности текста
15
  def analyze_sentiment(text):
 
46
  result = code_completion_pipeline(code, max_length=50, num_return_sequences=1)
47
  return result[0]['generated_text']
48
 
49
+ # Функция для определения фейковых новостей
50
+ def detect_fake_news(text):
51
+ result = fake_news_pipeline(text)[0]
52
+ return f"Label: {result['label']}, Confidence: {result['score']:.4f}"
53
+
54
  # Примеры текстов для анализа тональности
55
  sentiment_examples = [
56
  "I love programming, it's so much fun!",
 
104
  "for i in range(10):"
105
  ]
106
 
107
+ # Примеры текстов для определения фейковых новостей
108
+ fake_news_examples = [
109
+ "A new study shows that eating chocolate every day can make you live longer.",
110
+ "The government has secretly been working on time travel technology for decades.",
111
+ "Scientists have discovered a new planet in our solar system that is inhabited by aliens."
112
+ ]
113
+
114
  # Создаем интерфейс Gradio с вкладками
115
  with gr.Blocks() as demo:
116
  with gr.Tab("Sentiment Analysis"):
 
186
  examples=code_examples,
187
  examples_per_page=2
188
  )
189
+ with gr.Tab("Fake News Detection"):
190
+ gr.Interface(
191
+ fn=detect_fake_news,
192
+ inputs=gr.Textbox(lines=5, placeholder="Введите текст новости..."),
193
+ outputs="text",
194
+ title="Определение фейковых новостей",
195
+ description="Введите текст новости, чтобы определить, является ли она фейковой.",
196
+ examples=fake_news_examples,
197
+ examples_per_page=2
198
+ )
199
 
200
  # Запускаем интерфейс
201
  demo.launch()