Spaces:
Running
on
Zero
Running
on
Zero
aixsatoshi
commited on
Commit
•
13669f6
1
Parent(s):
3f86c47
Update app.py
Browse files
app.py
CHANGED
@@ -36,24 +36,65 @@ def mistral_inference(prompt, image_url):
|
|
36 |
|
37 |
return result
|
38 |
|
39 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
def process_input(text, image_url):
|
41 |
result = mistral_inference(text, image_url)
|
42 |
return result, image_url
|
43 |
|
|
|
|
|
|
|
|
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.
|
46 |
|
|
|
47 |
with gr.Row():
|
48 |
-
text_input = gr.Textbox(label="
|
49 |
-
image_input = gr.Textbox(label="
|
50 |
|
51 |
-
result_output = gr.Textbox(label="
|
52 |
-
image_output = gr.Image(label="
|
53 |
|
54 |
-
submit_button = gr.Button("
|
55 |
|
56 |
-
# ボタンをクリックすると、モデルの結果と画像を表示
|
57 |
submit_button.click(process_input, inputs=[text_input, image_input], outputs=[result_output, image_output])
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
demo.launch()
|
|
|
36 |
|
37 |
return result
|
38 |
|
39 |
+
# 言語によるUIラベルの設定
|
40 |
+
def get_labels(language):
|
41 |
+
labels = {
|
42 |
+
'en': {
|
43 |
+
'title': "Pixtral Model Image Description",
|
44 |
+
'text_prompt': "Text Prompt",
|
45 |
+
'image_url': "Image URL",
|
46 |
+
'output': "Model Output",
|
47 |
+
'image_display': "Input Image",
|
48 |
+
'submit': "Run Inference"
|
49 |
+
},
|
50 |
+
'zh': {
|
51 |
+
'title': "Pixtral模型图像描述",
|
52 |
+
'text_prompt': "文本提示",
|
53 |
+
'image_url': "图片网址",
|
54 |
+
'output': "模型输出",
|
55 |
+
'image_display': "输入图片",
|
56 |
+
'submit': "运行推理"
|
57 |
+
},
|
58 |
+
'jp': {
|
59 |
+
'title': "Pixtralモデルによる画像説明生成",
|
60 |
+
'text_prompt': "テキストプロンプト",
|
61 |
+
'image_url': "画像URL",
|
62 |
+
'output': "モデルの出力結果",
|
63 |
+
'image_display': "入力された画像",
|
64 |
+
'submit': "推論を実行"
|
65 |
+
}
|
66 |
+
}
|
67 |
+
return labels[language]
|
68 |
+
|
69 |
+
# Gradioインターフェース
|
70 |
def process_input(text, image_url):
|
71 |
result = mistral_inference(text, image_url)
|
72 |
return result, image_url
|
73 |
|
74 |
+
def update_ui(language):
|
75 |
+
labels = get_labels(language)
|
76 |
+
return labels['title'], labels['text_prompt'], labels['image_url'], labels['output'], labels['image_display'], labels['submit']
|
77 |
+
|
78 |
with gr.Blocks() as demo:
|
79 |
+
language_choice = gr.Dropdown(choices=['en', 'zh', 'jp'], label="Select Language", value='en')
|
80 |
|
81 |
+
title = gr.Markdown("## Pixtral Model Image Description")
|
82 |
with gr.Row():
|
83 |
+
text_input = gr.Textbox(label="Text Prompt", placeholder="e.g. Describe the image.")
|
84 |
+
image_input = gr.Textbox(label="Image URL", placeholder="e.g. https://example.com/image.png")
|
85 |
|
86 |
+
result_output = gr.Textbox(label="Model Output", lines=8, max_lines=20) # 高さ500ピクセルに相当するように調整
|
87 |
+
image_output = gr.Image(label="Input Image", type="auto") # 入力画像URLを表示するための場所
|
88 |
|
89 |
+
submit_button = gr.Button("Run Inference")
|
90 |
|
|
|
91 |
submit_button.click(process_input, inputs=[text_input, image_input], outputs=[result_output, image_output])
|
92 |
|
93 |
+
# 言語変更時にUIラベルを更新
|
94 |
+
language_choice.change(
|
95 |
+
fn=update_ui,
|
96 |
+
inputs=[language_choice],
|
97 |
+
outputs=[title, text_input, image_input, result_output, image_output, submit_button]
|
98 |
+
)
|
99 |
+
|
100 |
demo.launch()
|