Ilia-Iliev commited on
Commit
717e7a2
Β·
verified Β·
1 Parent(s): 4770700

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. app.py +2 -1
  2. community.py +9 -2
  3. communityview.py +9 -36
  4. creatorview.py +2 -1
app.py CHANGED
@@ -110,7 +110,7 @@ with gr.Blocks(
110
  with gr.Tabs() as tabs:
111
  for scen in REGISTRY.values():
112
  gameview.build_game(scen)
113
- comm_play, comm_inputs = communityview.build_community()
114
  play_btn, form = creatorview.build_creator()
115
  with gr.Tab("β–Ά Play your scenario", id=PLAY_TAB_ID):
116
  with gr.Row():
@@ -125,6 +125,7 @@ with gr.Blocks(
125
  comm_play.click(communityview.play_or_raise, comm_inputs, parse_state).success(
126
  do_load, parse_state, [tabs, *play_outs]
127
  )
 
128
  load_play.upload(load_scenario, load_play, play_outs)
129
  demo.load(warm_model)
130
 
 
110
  with gr.Tabs() as tabs:
111
  for scen in REGISTRY.values():
112
  gameview.build_game(scen)
113
+ comm_play, comm_inputs, comm_share = communityview.build_community()
114
  play_btn, form = creatorview.build_creator()
115
  with gr.Tab("β–Ά Play your scenario", id=PLAY_TAB_ID):
116
  with gr.Row():
 
125
  comm_play.click(communityview.play_or_raise, comm_inputs, parse_state).success(
126
  do_load, parse_state, [tabs, *play_outs]
127
  )
128
+ comm_share.click(lambda: gr.update(selected=creatorview.CREATOR_TAB_ID), None, tabs)
129
  load_play.upload(load_scenario, load_play, play_outs)
130
  demo.load(warm_model)
131
 
community.py CHANGED
@@ -56,8 +56,15 @@ def group_files(files):
56
 
57
 
58
  def _fetch(path):
59
- """One repo file as a local path (hub-cached, so refreshes only re-download changes)."""
60
- return hf_hub_download(_repo(), path, repo_type="dataset")
 
 
 
 
 
 
 
61
 
62
 
63
  def entries():
 
56
 
57
 
58
  def _fetch(path):
59
+ """One repo file as a local path (hub-cached, so refreshes only re-download changes).
60
+ Gradio only serves files from the app dir or the system temp dir β€” the hub cache is
61
+ neither, so each file is copied into temp once (entry folders are immutable)."""
62
+ cached = hf_hub_download(_repo(), path, repo_type="dataset")
63
+ dest = Path(tempfile.gettempdir()) / "rtr-community" / path
64
+ if not dest.exists():
65
+ dest.parent.mkdir(parents=True, exist_ok=True)
66
+ shutil.copy(cached, dest)
67
+ return str(dest)
68
 
69
 
70
  def entries():
communityview.py CHANGED
@@ -1,7 +1,6 @@
1
  """The 'Community' view: a gallery of scenarios other players shared β€” pick a card, read
2
- the premise, play it β€” plus a share box that publishes a saved .txt (+ optional picture)
3
- for everyone. The creator tab shares the same way through its own button; both land in the
4
- dataset that `community` wraps.
5
  """
6
 
7
  import gradio as gr
@@ -60,21 +59,10 @@ def play_or_raise(entries, picked):
60
  raise gr.Error(f"{creator.LOAD_ERROR}: {e}")
61
 
62
 
63
- def share_handler(path, image):
64
- if not path:
65
- raise gr.Error("Pick a scenario .txt to share")
66
- try:
67
- spec = creator.load_spec(path)
68
- creator.spec_to_scenario(spec) # publish only what actually plays
69
- community.publish(spec, image)
70
- except Exception as e: # invalid spec / missing config / failed upload
71
- raise gr.Error(f"Couldn't share: {e}")
72
- gr.Info("Shared 🌍 β€” hit Refresh to see it in the gallery")
73
-
74
-
75
  def build_community():
76
- """The Community tab. Returns (play_btn, inputs) for the top level to wire the
77
- Play-tab handoff β€” the same handshake the creator hands back."""
 
78
  with gr.Tab("🌍 Community") as tab:
79
  entries_state, picked = gr.State([]), gr.State()
80
  with gr.Row():
@@ -89,28 +77,13 @@ def build_community():
89
  )
90
  details = gr.Markdown()
91
  play_btn = gr.Button("Play it β–Ά", variant="primary")
92
-
93
- with gr.Accordion("Share yours", open=False):
94
- gr.Markdown(
95
- "Anyone can add a scenario: upload a saved .txt (the creator's ⬇️ Save"
96
- " format), add a picture if you like, and it appears here for everyone."
97
- )
98
- with gr.Row():
99
- spec_file = gr.File(
100
- label="Scenario (.txt)", file_types=[".txt"], type="filepath"
101
- )
102
- picture = gr.Image(
103
- label="Picture (optional)",
104
- type="filepath",
105
- sources=["upload"],
106
- height=160,
107
- )
108
- share_btn = gr.Button("🌍 Share it", scale=0)
109
 
110
  refresh_outs = [entries_state, gallery, status, picked, details]
111
  refresh_btn.click(refresh, None, refresh_outs)
112
  tab.select(ensure_loaded, entries_state, refresh_outs)
113
  gallery.select(select_handler, entries_state, [picked, details])
114
- share_btn.click(share_handler, [spec_file, picture], None)
115
 
116
- return play_btn, [entries_state, picked]
 
1
  """The 'Community' view: a gallery of scenarios other players shared β€” pick a card, read
2
+ the premise, play it. Sharing happens in the creator tab (its 🌍 button publishes the
3
+ form); this tab's Share-yours button just jumps there.
 
4
  """
5
 
6
  import gradio as gr
 
59
  raise gr.Error(f"{creator.LOAD_ERROR}: {e}")
60
 
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  def build_community():
63
+ """The Community tab. Returns (play_btn, inputs, share_btn) β€” the first two for the
64
+ top level to wire the Play-tab handoff (the same handshake the creator hands back),
65
+ the last to wire the jump to the creator tab."""
66
  with gr.Tab("🌍 Community") as tab:
67
  entries_state, picked = gr.State([]), gr.State()
68
  with gr.Row():
 
77
  )
78
  details = gr.Markdown()
79
  play_btn = gr.Button("Play it β–Ά", variant="primary")
80
+ share_btn = gr.Button(
81
+ "🌍 Share yours β€” make it in ✨ Create your own", size="sm"
82
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  refresh_outs = [entries_state, gallery, status, picked, details]
85
  refresh_btn.click(refresh, None, refresh_outs)
86
  tab.select(ensure_loaded, entries_state, refresh_outs)
87
  gallery.select(select_handler, entries_state, [picked, details])
 
88
 
89
+ return play_btn, [entries_state, picked], share_btn
creatorview.py CHANGED
@@ -13,6 +13,7 @@ import creator
13
  from dispositions import party_keys
14
 
15
  MAX_CAST = 6 # the editor pre-builds this many character cards and shows the live ones
 
16
  WHO = "Who" # the grid's display-only first column; cells are read by position, not header
17
 
18
 
@@ -238,7 +239,7 @@ def build_creator():
238
  idea; pressing Play hands it to the dedicated Play tab. Returns the refs the top-level
239
  needs to wire that handoff: (play_btn, form_inputs)."""
240
  blank = creator.blank_spec(3)
241
- with gr.Tab("✨ Create your own"):
242
  with gr.Row():
243
  idea = gr.Textbox(
244
  label="Your idea",
 
13
  from dispositions import party_keys
14
 
15
  MAX_CAST = 6 # the editor pre-builds this many character cards and shows the live ones
16
+ CREATOR_TAB_ID = "creator" # so other tabs (community's Share-yours) can jump here
17
  WHO = "Who" # the grid's display-only first column; cells are read by position, not header
18
 
19
 
 
239
  idea; pressing Play hands it to the dedicated Play tab. Returns the refs the top-level
240
  needs to wire that handoff: (play_btn, form_inputs)."""
241
  blank = creator.blank_spec(3)
242
+ with gr.Tab("✨ Create your own", id=CREATOR_TAB_ID):
243
  with gr.Row():
244
  idea = gr.Textbox(
245
  label="Your idea",