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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1,13 +1,14 @@
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
  emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
 
11
 
12
  # Функция для анализа тональности текста
13
  def analyze_sentiment(text):
@@ -39,6 +40,11 @@ def detect_emotion(text):
39
  result = emotion_pipeline(text)[0]
40
  return f"Emotion: {result['label']}, Confidence: {result['score']:.4f}"
41
 
 
 
 
 
 
42
  # Примеры текстов для анализа тональности
43
  sentiment_examples = [
44
  "I love programming, it's so much fun!",
@@ -85,6 +91,13 @@ emotion_examples = [
85
  "I am surprised by the results."
86
  ]
87
 
 
 
 
 
 
 
 
88
  # Создаем интерфейс Gradio с вкладками
89
  with gr.Blocks() as demo:
90
  with gr.Tab("Sentiment Analysis"):
@@ -150,6 +163,16 @@ with gr.Blocks() as demo:
150
  examples=emotion_examples,
151
  examples_per_page=2
152
  )
 
 
 
 
 
 
 
 
 
 
153
 
154
  # Запускаем интерфейс
155
  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")
8
  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):
 
40
  result = emotion_pipeline(text)[0]
41
  return f"Emotion: {result['label']}, Confidence: {result['score']:.4f}"
42
 
43
+ # Функция для автодополнения кода
44
+ 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!",
 
91
  "I am surprised by the results."
92
  ]
93
 
94
+ # Примеры кода для автодополнения
95
+ code_examples = [
96
+ "def factorial(n):",
97
+ "import numpy as np",
98
+ "for i in range(10):"
99
+ ]
100
+
101
  # Создаем интерфейс Gradio с вкладками
102
  with gr.Blocks() as demo:
103
  with gr.Tab("Sentiment Analysis"):
 
163
  examples=emotion_examples,
164
  examples_per_page=2
165
  )
166
+ with gr.Tab("Code Completion"):
167
+ gr.Interface(
168
+ fn=complete_code,
169
+ inputs=gr.Textbox(lines=5, placeholder="Введите начало кода..."),
170
+ outputs="text",
171
+ title="Автодополнение кода",
172
+ description="Введите начало кода, чтобы получить его продолжение.",
173
+ examples=code_examples,
174
+ examples_per_page=2
175
+ )
176
 
177
  # Запускаем интерфейс
178
  demo.launch()