import gradio as gr from transformers import pipeline # Hugging Faceの互換性のあるモデルをロード(image-to-textタスク用) model_name = "Salesforce/blip-image-captioning-base" 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 BLIP Model", description="Upload an image to get a descriptive text generated by the BLIP image captioning model." ) # Gradioアプリケーションの起動 iface.launch(server_name="0.0.0.0", server_port=7860)