Spaces:
Runtime error
Runtime error
File size: 852 Bytes
5cd0f39 f195801 5cd0f39 f195801 5cd0f39 f195801 90f3596 f195801 5cd0f39 f195801 5cd0f39 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import pipeline
# 创建 pipeline,使用指定模型进行图像到文本的转换
pipe = pipeline("image-to-text", model="microsoft/trocr-base-handwritten")
def recognize_text_from_image(input_image):
# 使用 pipeline 处理上传的图片
output = pipe(input_image)
# 返回识别出的文本
return output[0]['generated_text']
# 创建 Gradio 接口
iface = gr.Interface(
fn=recognize_text_from_image, # 指定处理函数
inputs=gr.Image(tool="editor", type="pil", label="Upload your image here or use your camera"), # 设置输入为图片
outputs="text", # 输出类型为文本
title="Image to Text Recognition", # 接口标题
description="Upload an image and the text in the image will be recognized." # 接口描述
)
# 启动 Gradio 应用
iface.launch()
|