huaapp / app_1.py
chanhua's picture
8
d336c8b verified
import gradio as gr
import testMch as func
def work(imgurl):
# output = testMch.describeImage2(img)
# # output = testMch.agent(img)
# # output = testMch.agent(img)
# return output
# imgurl = "r" + imgurl
# imgurl = imgurl.replace("\\\\\\", "\\")
# input = "Describe the following image:\n" + imgurl
out = func.agent(f"Please describe the following image:\n{imgurl}")
anws = func.toChinese(out['output'])
return anws
# with gr.Blocks() as demo:
# image_url = gr.Image(type="filepath", label="请选择一张图片")
# input = gr.Textbox(label='请描述您的问题', placeholder="", lines=1)
# output = gr.Textbox(label='答案', placeholder="", lines=2, interactive=False)
# submit = gr.Button('提问', variant="primary")
# submit.click(work, inputs=[image_url, input], outputs=output)
# demo.launch()
demo = gr.Interface(title="识别图片",
css="",
fn=work,
inputs=[gr.Image(type="filepath", label="请上传图片")],
outputs=[gr.Textbox(lines=3, label="识别结果")])
#
# # demo = gr.Interface(fn=work, inputs="image,text", outputs="text")
#
demo.launch()
# # interface = gr.Interface(fn=agent, inputs="image", outputs="text")
# # interface.launch()