Spaces:
Sleeping
Sleeping
File size: 2,290 Bytes
650ba4d 5862173 650ba4d 290e351 5862173 290e351 650ba4d 290e351 650ba4d 290e351 650ba4d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
from io import BytesIO
import docx
def process_input(uploaded_file, function):
if uploaded_file is not None:
# Определяем тип файла по расширению
if uploaded_file.name.endswith('.txt'):
# Если файл текстовый, читаем как текст
content = uploaded_file.read().decode("utf-8")
elif uploaded_file.name.endswith('.docx'):
# Если файл Word, используем библиотеку python-docx
doc = docx.Document(BytesIO(uploaded_file.read()))
content = '\n'.join([para.text for para in doc.paragraphs])
else:
return "Неподдерживаемый тип файла"
# Тут можно добавить логику обработки текста
return f"Результат для функции '{function}': {content[:100]}... (показаны первые 100 символов)"
return "Файл не загружен или пустой"
def main():
with gr.Blocks() as demo:
gr.Markdown("### AI Research Assistant")
with gr.Row():
file_input = gr.File(label="Загрузите файл")
function_select = gr.Dropdown(choices=[
"Суммаризатор", "Поиск новых статей", "Учитель", "Критик", "Тестировщик",
"Визуализатор связей", "Советник", "Соавтор", "Переводчик", "Аннотатор",
"Факт-чекер", "Аналитик данных", "Стилистический редактор", "Рецензент",
"Презентатор", "Грант-райтер", "Научный сторителлер", "Библиограф"
], label="Выберите функцию")
with gr.Row():
submit_button = gr.Button("Обработать")
output_text = gr.Textbox(label="Результат")
submit_button.click(
fn=process_input,
inputs=[file_input, function_select],
outputs=output_text
)
demo.launch()
if __name__ == "__main__":
main() |