Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Hugging Faceのモデルをロード(image-to-textタスク用)
|
5 |
+
model_name = "zhendongw/prompt-diffusion"
|
6 |
+
image_to_text = pipeline("image-to-text", model=model_name)
|
7 |
+
|
8 |
+
# Gradioの関数定義
|
9 |
+
def generate_text_from_image(image):
|
10 |
+
# 画像からテキストを生成
|
11 |
+
result = image_to_text(image)
|
12 |
+
return result[0]["generated_text"]
|
13 |
+
|
14 |
+
# Gradioインターフェースの設定
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=generate_text_from_image,
|
17 |
+
inputs=gr.Image(type="pil"),
|
18 |
+
outputs="text",
|
19 |
+
title="Image to Text with Prompt Diffusion",
|
20 |
+
description="Upload an image to get a descriptive text generated by zhendongw/prompt-diffusion model."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Gradioアプリケーションの起動
|
24 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|