Spaces:
Sleeping
Sleeping
import gradio as gr | |
import hashlib | |
def calculate_sha256(file_path): | |
"""Вычисляет SHA256 хеш файла.""" | |
hasher = hashlib.sha256() | |
with open(file_path, 'rb') as file: | |
while True: | |
chunk = file.read(4096) | |
if not chunk: | |
break | |
hasher.update(chunk) | |
return hasher.hexdigest() | |
def compare_files(file1, file2): | |
"""Сравнивает два файла на основе их SHA256 хеша.""" | |
if file1 is None or file2 is None: | |
return "Выберите оба файла." | |
hash1 = calculate_sha256(file1.name) | |
hash2 = calculate_sha256(file2.name) | |
if hash1 == hash2: | |
return "Файлы одинаковые." | |
else: | |
return "Файлы разные." | |
iface = gr.Interface( | |
fn=compare_files, | |
inputs=[ | |
gr.File(label="Файл 1"), | |
gr.File(label="Файл 2") | |
], | |
outputs="text", | |
title="Сравнение файлов по хешу SHA256", | |
description="Загрузите два файла для сравнения их хешей." | |
) | |
iface.launch() |