Spaces:
Sleeping
Sleeping
File size: 2,816 Bytes
b197a8c |
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 |
# components/campaign.py
import gradio as gr
from datetime import datetime
import json
import os
# Placeholder logic; replace with your own AI integration
def generate_campaign_concept(theme, level, players):
return f"**Campaign Theme:** {theme}\n**Starting Level:** {level}\n**Party Size:** {players}\n\nA mysterious prophecy drives the PCs into lost lands..."
def generate_session_content(campaign_summary, session_number):
return f"**Session {session_number} Outline:**\nThe heroes investigate a hidden temple, encounter guardians, and uncover a lost relic."
def save_to_gallery(content_type: str, data: dict, image_path=None):
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
os.makedirs("gallery", exist_ok=True)
filename = f"gallery/{content_type}_{timestamp}.json"
with open(filename, "w") as f:
json.dump({"type": content_type, "data": data, "image": image_path}, f, indent=2)
def campaign_tab():
with gr.TabItem("π² Campaign Planner"):
with gr.Row():
with gr.Column():
theme = gr.Dropdown(label="Campaign Theme", choices=["High Fantasy", "Dark Fantasy", "Mystery", "Political Intrigue"], value="High Fantasy")
level = gr.Slider(label="Starting Level", minimum=1, maximum=20, step=1, value=5)
players = gr.Slider(label="Party Size", minimum=1, maximum=8, step=1, value=4)
gen_campaign_btn = gr.Button("π― Generate Campaign Concept")
campaign_output = gr.Markdown(label="Campaign Summary")
session_num = gr.Slider(label="Session Number", minimum=1, maximum=20, step=1, value=1)
gen_session_btn = gr.Button("π Generate Session Outline")
session_output = gr.Markdown(label="Session Outline")
with gr.Column():
export_campaign = gr.Button("πΎ Save Campaign to Gallery")
export_campaign_output = gr.Textbox(label="Export Status")
# Actions
gen_campaign_btn.click(
generate_campaign_concept,
inputs=[theme, level, players],
outputs=[campaign_output]
)
gen_session_btn.click(
generate_session_content,
inputs=[campaign_output, session_num],
outputs=[session_output]
)
export_campaign.click(
lambda th, lv, pl, camp: save_to_gallery(
"campaign",
{
"theme": th,
"level": lv,
"players": pl,
"campaign_summary": camp
}
) or "β
Campaign saved!",
inputs=[theme, level, players, campaign_output],
outputs=[export_campaign_output]
)
|