Spaces:
Sleeping
Sleeping
File size: 1,124 Bytes
5200e46 |
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 |
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() |