Spaces:
Sleeping
Sleeping
Delete pages/Project.py
Browse files- pages/Project.py +0 -108
pages/Project.py
DELETED
@@ -1,108 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import requests
|
4 |
-
from wordcloud import WordCloud
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
-
import os
|
7 |
-
import re
|
8 |
-
|
9 |
-
# Установка API URL и заголовков
|
10 |
-
API_URL_tra = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-ru"
|
11 |
-
API_URL_key = "https://api-inference.huggingface.co/models/ml6team/keyphrase-extraction-kbir-inspec"
|
12 |
-
API_URL_sum = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
13 |
-
|
14 |
-
headers = {"Authorization": os.getenv("api_token")}
|
15 |
-
|
16 |
-
|
17 |
-
# Функция для получения ключевых слов
|
18 |
-
def get_key_words(payload):
|
19 |
-
response = requests.post(API_URL_key, headers=headers, json=payload)
|
20 |
-
return response.json()
|
21 |
-
|
22 |
-
# Функция для перевода слова
|
23 |
-
def translate_key_words(payload):
|
24 |
-
response = requests.post(API_URL_tra, headers=headers, json=payload)
|
25 |
-
return response.json()
|
26 |
-
|
27 |
-
# Функция для составления конспекта
|
28 |
-
def make_summary(payload):
|
29 |
-
response = requests.post(API_URL_sum, headers=headers, json=payload)
|
30 |
-
return response.json()
|
31 |
-
|
32 |
-
|
33 |
-
# Очищаем список слов
|
34 |
-
def clean_list(words_list):
|
35 |
-
cleaned_words_list = []
|
36 |
-
for word in words_list:
|
37 |
-
word = word.lower()
|
38 |
-
word =re.sub(r"[^а-яА-Яa-zA-Z\s]", "", word)
|
39 |
-
word = word.lstrip()
|
40 |
-
word = word.rstrip()
|
41 |
-
cleaned_words_list.append(word)
|
42 |
-
return cleaned_words_list
|
43 |
-
|
44 |
-
|
45 |
-
# Настраеваем заголовок и название страницы
|
46 |
-
st.set_page_config(layout="wide", page_title="Students' Personal Assistant")
|
47 |
-
st.markdown(' # :female-student: Персональный помощник для студентов')
|
48 |
-
|
49 |
-
st.divider()
|
50 |
-
st.markdown('# :blue_book: Конспект на английском языке')
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
col1, col2 = st.columns(2)
|
55 |
-
text_from_tarea = col1.text_area('Введите тект статьи на английском языке', height=500)
|
56 |
-
|
57 |
-
|
58 |
-
button_start = st.button('Обработать текст')
|
59 |
-
|
60 |
-
key_words_list = []
|
61 |
-
if button_start:
|
62 |
-
|
63 |
-
with st.spinner('...'):
|
64 |
-
# Составляем конспект
|
65 |
-
summary_text = make_summary({"inputs": text_from_tarea})
|
66 |
-
col2.text_area('Конспект статьи', height=500, value=summary_text[0]['summary_text'])
|
67 |
-
|
68 |
-
# Извлекаем ключевые слова
|
69 |
-
kew_words = get_key_words({ "inputs": text_from_tarea,})
|
70 |
-
for key_word in kew_words :
|
71 |
-
key_words_list.append(key_word['word'].lower())
|
72 |
-
|
73 |
-
sorted_keywords = set(sorted(key_words_list))
|
74 |
-
sorted_keywords = clean_list(sorted_keywords)
|
75 |
-
|
76 |
-
# Переводим ключевые слова
|
77 |
-
translated_words_list = []
|
78 |
-
for key_word in sorted_keywords:
|
79 |
-
res = translate_key_words({"inputs": key_word,})
|
80 |
-
translated_words_list.append(res[0]['translation_text'])
|
81 |
-
|
82 |
-
# Создаем карточки
|
83 |
-
cleaned_words_list_ru = clean_list(translated_words_list)
|
84 |
-
cards_list = []
|
85 |
-
for item1, item2 in zip(sorted_keywords, cleaned_words_list_ru):
|
86 |
-
cards_list.append([item1, item2])
|
87 |
-
|
88 |
-
|
89 |
-
st.success('Готово')
|
90 |
-
|
91 |
-
# Выводим Word Cloud
|
92 |
-
st.set_option('deprecation.showPyplotGlobalUse', False)
|
93 |
-
words_str = ', '.join(sorted_keywords)
|
94 |
-
w = WordCloud(background_color="white").generate(words_str)
|
95 |
-
plt.imshow(w, interpolation='bilinear')
|
96 |
-
plt.imshow(w)
|
97 |
-
plt.axis("off")
|
98 |
-
st.pyplot()
|
99 |
-
|
100 |
-
# Выводим карточки
|
101 |
-
st.markdown('# :bookmark_tabs: Карточки из ключевых слов')
|
102 |
-
for el in cards_list:
|
103 |
-
with st.chat_message("assistant"):
|
104 |
-
#st.divider()
|
105 |
-
st.markdown('# :flower_playing_cards:')
|
106 |
-
st.markdown(f'# :green[{el[0]}]')
|
107 |
-
st.markdown(f'## :blue[{el[1]}]')
|
108 |
-
st.divider()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|