image-prompt / app.py
soiz's picture
Create app.py
d9e7df5 verified
raw
history blame
808 Bytes
import gradio as gr
from transformers import pipeline
# Hugging Faceのモデルをロード(image-to-textタスク用)
model_name = "zhendongw/prompt-diffusion"
image_to_text = pipeline("image-to-text", model=model_name)
# Gradioの関数定義
def generate_text_from_image(image):
# 画像からテキストを生成
result = image_to_text(image)
return result[0]["generated_text"]
# Gradioインターフェースの設定
iface = gr.Interface(
fn=generate_text_from_image,
inputs=gr.Image(type="pil"),
outputs="text",
title="Image to Text with Prompt Diffusion",
description="Upload an image to get a descriptive text generated by zhendongw/prompt-diffusion model."
)
# Gradioアプリケーションの起動
iface.launch(server_name="0.0.0.0", server_port=7860)