Felguk commited on
Commit
877758a
·
verified ·
1 Parent(s): 23dd2b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
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
- speech_to_text_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-small")
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 transcribe_audio(audio):
33
- result = speech_to_text_pipeline(audio)
34
- return result['text']
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
- audio_examples = [
68
- "https://lazypy.ro/tts/assets/audio/StreamElements_Nicole_5c029bf08a515afb40579f0cd0c028bf.mp3", # Пример 1
69
- "https://lazypy.ro/tts/assets/audio/Bing_en-US-EricNeural_e2ca58109fc0206fb0d201689ca2bc8f.mp3" # Пример 2
 
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("Speech-to-Text Transcription"):
118
  gr.Interface(
119
- fn=transcribe_audio,
120
- inputs=gr.Audio(type="filepath", label="Загрузите аудиофайл"),
121
  outputs="text",
122
- title="Расшифровка аудио в текст(сломаный)",
123
- description="Загрузите аудиофайл, чтобы получить его текстовую расшифровку.",
124
- examples=audio_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