Felguk commited on
Commit
6ef9655
·
verified ·
1 Parent(s): 0527733

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения кода, определения фейковых новостей и NER
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
  summarization_pipeline = pipeline("summarization")
7
  image_captioning_pipeline = pipeline("image-to-text")
@@ -11,6 +11,7 @@ emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distil
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
  ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", grouped_entities=True)
 
14
 
15
  # Функция для анализа тональности текста
16
  def analyze_sentiment(text):
@@ -60,6 +61,14 @@ def recognize_entities(text):
60
  entities.append(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Confidence: {entity['score']:.4f}")
61
  return "\n".join(entities)
62
 
 
 
 
 
 
 
 
 
63
  # Примеры текстов для анализа тональности
64
  sentiment_examples = [
65
  "I love programming, it's so much fun!",
@@ -127,6 +136,13 @@ ner_examples = [
127
  "Elon Musk is the CEO of Tesla and SpaceX."
128
  ]
129
 
 
 
 
 
 
 
 
130
  # Создаем интерфейс Gradio с вкладками
131
  with gr.Blocks() as demo:
132
  with gr.Tab("Sentiment Analysis"):
@@ -222,6 +238,16 @@ with gr.Blocks() as demo:
222
  examples=ner_examples,
223
  examples_per_page=2
224
  )
 
 
 
 
 
 
 
 
 
 
225
 
226
  # Запускаем интерфейс
227
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения кода, определения фейковых новостей, NER и классификации изображений
5
  sentiment_pipeline = pipeline("sentiment-analysis")
6
  summarization_pipeline = pipeline("summarization")
7
  image_captioning_pipeline = pipeline("image-to-text")
 
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
  ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", grouped_entities=True)
14
+ image_classification_pipeline = pipeline("image-classification", model="google/vit-base-patch16-224")
15
 
16
  # Функция для анализа тональности текста
17
  def analyze_sentiment(text):
 
61
  entities.append(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Confidence: {entity['score']:.4f}")
62
  return "\n".join(entities)
63
 
64
+ # Функция для классификации изображений
65
+ def classify_image(image):
66
+ result = image_classification_pipeline(image)
67
+ classifications = []
68
+ for item in result:
69
+ classifications.append(f"Label: {item['label']}, Confidence: {item['score']:.4f}")
70
+ return "\n".join(classifications)
71
+
72
  # Примеры текстов для анализа тональности
73
  sentiment_examples = [
74
  "I love programming, it's so much fun!",
 
136
  "Elon Musk is the CEO of Tesla and SpaceX."
137
  ]
138
 
139
+ # Примеры изображений для классификации
140
+ classification_examples = [
141
+ "https://a.d-cd.net/b977306s-1920.jpg", # Пример 1
142
+ "https://i.pinimg.com/originals/ba/bd/6d/babd6d37eb2dd965c7f1dfb516d54094.jpg", # Пример 2
143
+ "https://get.wallhere.com/photo/sea-bay-water-beach-coast-swimming-pool-resort-island-lagoon-Caribbean-vacation-estate-leisure-ocean-tropics-2560x1440-px-geographical-feature-atoll-554636.jpg" # Пример 3
144
+ ]
145
+
146
  # Создаем интерфейс Gradio с вкладками
147
  with gr.Blocks() as demo:
148
  with gr.Tab("Sentiment Analysis"):
 
238
  examples=ner_examples,
239
  examples_per_page=2
240
  )
241
+ with gr.Tab("Image Classification"):
242
+ gr.Interface(
243
+ fn=classify_image,
244
+ inputs=gr.Image(type="pil", label="Загрузите изображение"),
245
+ outputs="text",
246
+ title="Классификация изображений",
247
+ description="Загрузите изображение, чтобы классифицировать его.",
248
+ examples=classification_examples,
249
+ examples_per_page=2
250
+ )
251
 
252
  # Запускаем интерфейс
253
  demo.launch()