Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
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")
|
8 |
qa_pipeline = pipeline("question-answering")
|
9 |
-
|
10 |
|
11 |
# Функция для анализа тональности текста
|
12 |
def analyze_sentiment(text):
|
@@ -28,10 +28,10 @@ def answer_question(context, question):
|
|
28 |
result = qa_pipeline(question=question, context=context)
|
29 |
return f"Answer: {result['answer']}, Confidence: {result['score']:.4f}"
|
30 |
|
31 |
-
# Функция для
|
32 |
-
def
|
33 |
-
result =
|
34 |
-
return result['
|
35 |
|
36 |
# Примеры текстов для анализа тональности
|
37 |
sentiment_examples = [
|
@@ -63,10 +63,11 @@ qa_examples = [
|
|
63 |
["Artificial intelligence is transforming industries by automating tasks and providing insights from large datasets.", "How is AI transforming industries?"]
|
64 |
]
|
65 |
|
66 |
-
# Примеры
|
67 |
-
|
68 |
-
"
|
69 |
-
"
|
|
|
70 |
]
|
71 |
|
72 |
# Создаем интерфейс Gradio с вкладками
|
@@ -114,14 +115,14 @@ with gr.Blocks() as demo:
|
|
114 |
examples=qa_examples,
|
115 |
examples_per_page=2
|
116 |
)
|
117 |
-
with gr.Tab("
|
118 |
gr.Interface(
|
119 |
-
fn=
|
120 |
-
inputs=gr.
|
121 |
outputs="text",
|
122 |
-
title="
|
123 |
-
description="
|
124 |
-
examples=
|
125 |
examples_per_page=2
|
126 |
)
|
127 |
|
|
|
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")
|
8 |
qa_pipeline = pipeline("question-answering")
|
9 |
+
translation_pipeline = pipeline("translation_en_to_ru", model="Helsinki-NLP/opus-mt-en-ru")
|
10 |
|
11 |
# Функция для анализа тональности текста
|
12 |
def analyze_sentiment(text):
|
|
|
28 |
result = qa_pipeline(question=question, context=context)
|
29 |
return f"Answer: {result['answer']}, Confidence: {result['score']:.4f}"
|
30 |
|
31 |
+
# Функция для перевода текста
|
32 |
+
def translate_text(text):
|
33 |
+
result = translation_pipeline(text)
|
34 |
+
return result[0]['translation_text']
|
35 |
|
36 |
# Примеры текстов для анализа тональности
|
37 |
sentiment_examples = [
|
|
|
63 |
["Artificial intelligence is transforming industries by automating tasks and providing insights from large datasets.", "How is AI transforming industries?"]
|
64 |
]
|
65 |
|
66 |
+
# Примеры текстов для перевода
|
67 |
+
translation_examples = [
|
68 |
+
"Hello, how are you?",
|
69 |
+
"I love machine learning and artificial intelligence.",
|
70 |
+
"The weather is beautiful today."
|
71 |
]
|
72 |
|
73 |
# Создаем интерфейс Gradio с вкладками
|
|
|
115 |
examples=qa_examples,
|
116 |
examples_per_page=2
|
117 |
)
|
118 |
+
with gr.Tab("Language Translation"):
|
119 |
gr.Interface(
|
120 |
+
fn=translate_text,
|
121 |
+
inputs=gr.Textbox(lines=2, placeholder="Введите текст на английском..."),
|
122 |
outputs="text",
|
123 |
+
title="Перевод текста (английский → русский)",
|
124 |
+
description="Введите текст на английском, чтобы перевести его на русский.",
|
125 |
+
examples=translation_examples,
|
126 |
examples_per_page=2
|
127 |
)
|
128 |
|