Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import base64
|
| 3 |
import hashlib
|
| 4 |
import io
|
| 5 |
import requests
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
-
def
|
| 9 |
"""
|
| 10 |
-
从URL获取图片,返回其
|
| 11 |
|
| 12 |
Args:
|
| 13 |
image_url (str): 图片URL地址
|
| 14 |
|
| 15 |
Returns:
|
| 16 |
-
|
| 17 |
"""
|
| 18 |
try:
|
| 19 |
# 从URL获取图片
|
|
@@ -27,32 +26,22 @@ def process_image_url(image_url):
|
|
| 27 |
if image.mode != 'RGB':
|
| 28 |
image = image.convert('RGB')
|
| 29 |
|
| 30 |
-
#
|
| 31 |
buffered = io.BytesIO()
|
| 32 |
image.save(buffered, format="JPEG")
|
| 33 |
-
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 34 |
-
|
| 35 |
-
# 计算MD5值
|
| 36 |
md5_hash = hashlib.md5(buffered.getvalue()).hexdigest()
|
| 37 |
|
| 38 |
-
return
|
| 39 |
-
"base64": img_str,
|
| 40 |
-
"md5": md5_hash,
|
| 41 |
-
"status": "success"
|
| 42 |
-
}
|
| 43 |
except Exception as e:
|
| 44 |
-
return {
|
| 45 |
-
"error": str(e),
|
| 46 |
-
"status": "failed"
|
| 47 |
-
}
|
| 48 |
|
| 49 |
# 创建Gradio界面
|
| 50 |
app = gr.Interface(
|
| 51 |
-
fn=
|
| 52 |
inputs=gr.Textbox(label="图片URL", placeholder="请输入图片URL地址"),
|
| 53 |
-
outputs=gr.
|
| 54 |
-
title="图片
|
| 55 |
-
description="输入图片URL,获取图片的
|
| 56 |
)
|
| 57 |
|
| 58 |
# 启动应用
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import hashlib
|
| 3 |
import io
|
| 4 |
import requests
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
def get_image_md5(image_url):
|
| 8 |
"""
|
| 9 |
+
从URL获取图片,返回其MD5值
|
| 10 |
|
| 11 |
Args:
|
| 12 |
image_url (str): 图片URL地址
|
| 13 |
|
| 14 |
Returns:
|
| 15 |
+
str: 图片的MD5值
|
| 16 |
"""
|
| 17 |
try:
|
| 18 |
# 从URL获取图片
|
|
|
|
| 26 |
if image.mode != 'RGB':
|
| 27 |
image = image.convert('RGB')
|
| 28 |
|
| 29 |
+
# 计算MD5值
|
| 30 |
buffered = io.BytesIO()
|
| 31 |
image.save(buffered, format="JPEG")
|
|
|
|
|
|
|
|
|
|
| 32 |
md5_hash = hashlib.md5(buffered.getvalue()).hexdigest()
|
| 33 |
|
| 34 |
+
return md5_hash
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
+
return f"错误: {str(e)}"
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# 创建Gradio界面
|
| 39 |
app = gr.Interface(
|
| 40 |
+
fn=get_image_md5,
|
| 41 |
inputs=gr.Textbox(label="图片URL", placeholder="请输入图片URL地址"),
|
| 42 |
+
outputs=gr.Textbox(label="MD5值"),
|
| 43 |
+
title="图片MD5生成器",
|
| 44 |
+
description="输入图片URL,获取图片的MD5值"
|
| 45 |
)
|
| 46 |
|
| 47 |
# 启动应用
|