import gradio as gr import random def generate_sentence(num_animals, animal_type, countries, location, activities, time_of_day): country_str = ", ".join(countries) activity_str = ", ".join(activities) time = "아침" if time_of_day else "저녁" sentence = f"{country_str}에서 온 {num_animals}마리의 {animal_type}이 {location}에서 {activity_str} 했습니다. {time}까지." return sentence with gr.Blocks() as demo: with gr.Row(): with gr.Column(): num_slider = gr.Slider(minimum=2, maximum=20, step=1, label="동물 수량", value=2) animal_dropdown = gr.Dropdown( choices=["강아지", "고양이", "토끼", "햄스터", "앵무새"], label="동물 종류", value="강아지" ) countries = gr.CheckboxGroup( choices=["한국", "일본", "중국", "미국", "영국"], label="국가 선택" ) location = gr.Radio( choices=["공원", "해변", "산", "강가", "숲"], label="장소", value="공원" ) activities = gr.Dropdown( choices=["달리기", "수영", "잠자기", "놀기", "먹기"], label="활동", multiselect=True ) time_checkbox = gr.Checkbox(label="아침(체크) / 저녁(미체크)") with gr.Column(): output_text = gr.Textbox(label="생성된 문장") generate_btn = gr.Button("문장 생성하기") generate_btn.click( fn=generate_sentence, inputs=[num_slider, animal_dropdown, countries, location, activities, time_checkbox], outputs=output_text ) if __name__ == '__main__': demo.launch()