Spaces:
Runtime error
Runtime error
import streamlit as st | |
import json | |
import shutil | |
from common.tinderwrapper import TinderWrapper | |
from common.helpers import create_folder, save_data | |
with open('config.json', 'r') as f: | |
config = json.load(f) | |
APP_NAME = config['APP_NAME'] | |
APP_LOGO = config['APP_LOGO'] | |
APP_DESCRIPTION = config['APP_DESCRIPTION'] | |
DUMP_FOLDER = config['DUMP_FOLDER'] | |
def update_progress(percent, text): | |
progress_bar.progress(percent) | |
status_text.text(text) | |
st.set_page_config(page_title=APP_NAME) | |
st.title(APP_NAME) | |
st.image(APP_LOGO, use_column_width=True) | |
st.markdown(APP_DESCRIPTION) | |
access_token = st.text_input('Tinder Access Token', help='Токен доступа, полученный из запроса Tinder') | |
if st.button('Запуск'): | |
if not access_token: | |
st.error('Необходимо задать токен доступа') | |
else: | |
progress_bar = st.progress(0) | |
status_text = st.empty() | |
wrapper = TinderWrapper(access_token) | |
create_folder(DUMP_FOLDER) | |
try: | |
dump = wrapper.create_dump(update_progress) | |
save_data(dump, DUMP_FOLDER, update_progress) | |
shutil.make_archive('output', 'zip', DUMP_FOLDER) | |
update_progress(1.0, 'Обработка успешно завершена!') | |
with open('output.zip', 'rb') as f: | |
st.download_button('Скачать архив', f, file_name='output.zip') | |
except Exception as e: | |
st.error(e) | |
update_progress(1.0, 'Возникла ошибка!') |