Spaces:
Sleeping
Sleeping
Delete pages/Cards.py
Browse files- pages/Cards.py +0 -59
pages/Cards.py
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import requests
|
4 |
-
import os
|
5 |
-
|
6 |
-
# Установка API URL и заголовков
|
7 |
-
API_URL_gen = "https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill"
|
8 |
-
API_URL_tra = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-ru"
|
9 |
-
|
10 |
-
headers = {"Authorization": os.getenv("api_token")}
|
11 |
-
|
12 |
-
# Функция для генерирования предложения
|
13 |
-
def generate_example(payload):
|
14 |
-
response = requests.post(API_URL_gen, headers=headers, json=payload)
|
15 |
-
return response.json()
|
16 |
-
|
17 |
-
# Функция для перевода слова
|
18 |
-
def translate_word(payload):
|
19 |
-
response = requests.post(API_URL_tra, headers=headers, json=payload)
|
20 |
-
return response.json()
|
21 |
-
|
22 |
-
# Настраеваем заголовок и название страницы
|
23 |
-
st.set_page_config(layout="wide", page_title="Students' Personal Assistant")
|
24 |
-
st.markdown(' # :female-student: Персональный помощник для студентов')
|
25 |
-
st.divider()
|
26 |
-
st.markdown('## :flower_playing_cards: Карточки для изучения английских слов')
|
27 |
-
|
28 |
-
st.markdown('# :bookmark_tabs: :bookmark_tabs: :bookmark_tabs: :bookmark_tabs: ')
|
29 |
-
words_from_tarea = st.text_area('Напиши список слов на английском', value='regularization learning dropout rate')
|
30 |
-
button_start = st.button('Создать карточки')
|
31 |
-
|
32 |
-
cards_list = list()
|
33 |
-
if button_start:
|
34 |
-
words_list = words_from_tarea.split()
|
35 |
-
st.divider()
|
36 |
-
|
37 |
-
|
38 |
-
# Отправляем запросы через API для получения перевода слов и генерирования предложений
|
39 |
-
with st.spinner('...'):
|
40 |
-
for word in words_list:
|
41 |
-
example = generate_example({"text": word})
|
42 |
-
translated = translate_word({"inputs": word})
|
43 |
-
cards_list.append([word, translated[0]['translation_text'].lower(), example['generated_text']])
|
44 |
-
|
45 |
-
# Преобразуем полученные данные в DataFrame
|
46 |
-
#cards_df = pd.DataFrame(cards_list, columns=['word', 'translated', 'example'])
|
47 |
-
st.success('Готово')
|
48 |
-
|
49 |
-
# Выводим карточки
|
50 |
-
for el in cards_list:
|
51 |
-
with st.chat_message("assistant"):
|
52 |
-
#st.divider()
|
53 |
-
st.markdown('# :flower_playing_cards:')
|
54 |
-
st.markdown(f'# :red[{el[0]}]')
|
55 |
-
st.markdown(f'## :blue[{el[1]}]')
|
56 |
-
st.markdown(f'* {el[2]}')
|
57 |
-
st.divider()
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|