-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (50 loc) · 1.77 KB
/
app.py
File metadata and controls
70 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
from inference import classify
from image_captioning.one_image_captioning import captioning
def get_classification_ui(predictions):
"""
분류 결과 UI를 반환합니다.
:param predictions: 예측 결과 리스트 ([(class_name, probability), ...])
:return: HTML 및 그래프 출력
"""
# 결과 HTML 텍스트 생성
html_result = "<h2>Top Predictions</h2>"
for label, score in predictions:
html_result += f"<p><strong>{label}:</strong> {score:.2f}%</p>"
return html_result
def get_caption_ui(caption):
"""
캡션 결과 UI를 반환합니다.
:param caption: 이미지 캡션 문자열
:return: HTML 출력
"""
# 결과 HTML 텍스트 생성
html_result = f"<h2>Generated Caption</h2><p>{caption}</p>"
return html_result
def update_classification_ui(image_input):
predictions = classify(image_input)
classification_html = get_classification_ui(predictions)
return classification_html
def update_caption_ui(image_input):
caption = captioning(image_input)
caption_html = get_caption_ui(caption)
return caption_html
def on_click(image_input):
classification_html = update_classification_ui(image_input)
caption_html = update_caption_ui(image_input)
return classification_html, caption_html
# Gradio 인터페이스 생성
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
image_input = gr.Image()
predict_button = gr.Button("Run Prediction")
with gr.Column():
classification_output = gr.HTML()
caption_output = gr.HTML()
predict_button.click(
fn=on_click,
inputs=image_input,
outputs=[classification_output, caption_output],
)
demo.launch(share=True)