import gradio as gr import random # Стан NPC npc_states = { "початковий": "NPC переживає перші кроки самопізнання.", "в пошуку": "NPC намагається знайти свій шлях у світі.", "світлий": "NPC став провідником для інших, пізнав світло.", "бог": "NPC досяг стану бога і управляє космічним порядком." } # Статуси гри game_status = { "active": "Гра триває. NPC розвивається.", "victory": "Ви виграли! NPC досяг стану бога.", "defeat": "Ви програли... Сумніви зупинили прогрес." } # Глобальні змінні current_game_status = "active" current_npc_state = "початковий" # Функція оновлення NPC def update_npc_state(): global current_npc_state states = list(npc_states.keys()) current_index = states.index(current_npc_state) if current_index < len(states) - 1: current_npc_state = states[current_index + 1] else: global current_game_status current_game_status = "victory" # Основна функція для взаємодії def interact_with_npc(choice): global current_game_status if current_game_status != "active": return game_status[current_game_status], npc_states[current_npc_state] if choice == "1": # Вперед update_npc_state() message = "NPC зробив крок вперед!" elif choice == "2": # Сумніви current_game_status = "defeat" message = "NPC зупинився через ваші сумніви." else: message = "Некоректний вибір. NPC очікує вашого рішення." return game_status[current_game_status], npc_states[current_npc_state] # Інтерфейс Gradio def reset_game(): global current_game_status, current_npc_state current_game_status = "active" current_npc_state = "початковий" return "active", npc_states["початковий"] with gr.Blocks() as demo: gr.Markdown("## NPC Familia: Духовний розвиток вашого персонажа") current_status = gr.Textbox(label="Статус гри", value="active", interactive=False) current_state = gr.Textbox(label="Стан NPC", value=npc_states["початковий"], interactive=False) with gr.Row(): btn_forward = gr.Button("Крок вперед") btn_doubt = gr.Button("Сумніви") btn_reset = gr.Button("Почати заново") btn_forward.click(fn=lambda: interact_with_npc("1"), inputs=[], outputs=[current_status, current_state]) btn_doubt.click(fn=lambda: interact_with_npc("2"), inputs=[], outputs=[current_status, current_state]) btn_reset.click(fn=reset_game, inputs=[], outputs=[current_status, current_state]) demo.launch()