burtenshaw HF Staff commited on
Commit
9023a14
·
verified ·
1 Parent(s): 98ad17f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +1 -158
app.py CHANGED
@@ -1,44 +1,4 @@
1
 
2
- import gradio as gr
3
- from app import demo as app
4
- import os
5
-
6
- _docs = {'WordleBoard': {'description': 'Interactive Wordle board component.', 'members': {'__init__': {'word_length': {'type': 'int', 'default': '5', 'description': None}, 'max_attempts': {'type': 'int', 'default': '6', 'description': None}, 'return': {'type': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'typing.Union[\n gradio_wordleboard.wordleboard.PublicWordleState,\n typing.Dict,\n str,\n NoneType,\n][PublicWordleState, Dict, str, None]', 'description': None}}, 'preprocess': {'return': {'type': 'typing.Optional[typing.Dict][Dict, None]', 'description': "The preprocessed input data sent to the user's function in the backend."}, 'value': None}}, 'events': {}}, '__meta__': {'additional_interfaces': {'PublicWordleState': {'source': '@dataclass\nclass PublicWordleState:\n board: List[WordleRow]\n current_row: int\n status: str\n message: str\n max_rows: int', 'refs': ['WordleRow']}, 'WordleRow': {'source': '@dataclass\nclass WordleRow:\n letters: List[str] = field(\n default_factory=lambda: [""] * 5\n )\n statuses: List[TileStatus] = field(\n default_factory=lambda: ["empty"] * 5\n )'}}, 'user_fn_refs': {'WordleBoard': ['PublicWordleState']}}}
7
-
8
- abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
-
10
- with gr.Blocks(
11
- css=abs_path,
12
- theme=gr.themes.Default(
13
- font_mono=[
14
- gr.themes.GoogleFont("Inconsolata"),
15
- "monospace",
16
- ],
17
- ),
18
- ) as demo:
19
- gr.Markdown(
20
- """
21
- # `gradio_wordleboard`
22
-
23
- <div style="display: flex; gap: 7px;">
24
- <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
- </div>
26
-
27
- A custom Gradio component that renders and plays the Wordle word game
28
- """, elem_classes=["md-custom"], header_links=True)
29
- app.render()
30
- gr.Markdown(
31
- """
32
- ## Installation
33
-
34
- ```bash
35
- pip install gradio_wordleboard
36
- ```
37
-
38
- ## Usage
39
-
40
- ```python
41
-
42
  from __future__ import annotations
43
 
44
  import asyncio
@@ -159,14 +119,7 @@ async def inference_handler(api_key: str) -> AsyncIterator[str]:
159
  raise RuntimeError("HF_TOKEN or API_KEY environment variable must be set.")
160
 
161
  client = AsyncOpenAI(base_url=API_BASE_URL, api_key=api_key)
162
- env = TextArenaEnv.from_docker_image(
163
- DOCKER_IMAGE,
164
- env_vars={
165
- "TEXTARENA_ENV_ID": "Wordle-v0",
166
- "TEXTARENA_NUM_PLAYERS": "1",
167
- },
168
- ports={8000: 8000},
169
- )
170
 
171
  try:
172
  async for result in _play_wordle(env, client):
@@ -217,113 +170,3 @@ if __name__ == "__main__":
217
  raise SystemExit("HF_TOKEN (or API_KEY) must be set to query the model.")
218
 
219
  demo.launch()
220
-
221
- ```
222
- """, elem_classes=["md-custom"], header_links=True)
223
-
224
-
225
- gr.Markdown("""
226
- ## `WordleBoard`
227
-
228
- ### Initialization
229
- """, elem_classes=["md-custom"], header_links=True)
230
-
231
- gr.ParamViewer(value=_docs["WordleBoard"]["members"]["__init__"], linkify=['PublicWordleState', 'WordleRow'])
232
-
233
-
234
-
235
-
236
- gr.Markdown("""
237
-
238
- ### User function
239
-
240
- The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
241
-
242
- - When used as an Input, the component only impacts the input signature of the user function.
243
- - When used as an output, the component only impacts the return signature of the user function.
244
-
245
- The code snippet below is accurate in cases where the component is used as both an input and an output.
246
-
247
- - **As input:** Is passed, the preprocessed input data sent to the user's function in the backend.
248
-
249
-
250
- ```python
251
- def predict(
252
- value: typing.Optional[typing.Dict][Dict, None]
253
- ) -> typing.Union[
254
- gradio_wordleboard.wordleboard.PublicWordleState,
255
- typing.Dict,
256
- str,
257
- NoneType,
258
- ][PublicWordleState, Dict, str, None]:
259
- return value
260
- ```
261
- """, elem_classes=["md-custom", "WordleBoard-user-fn"], header_links=True)
262
-
263
-
264
-
265
-
266
- code_PublicWordleState = gr.Markdown("""
267
- ## `PublicWordleState`
268
- ```python
269
- @dataclass
270
- class PublicWordleState:
271
- board: List[WordleRow]
272
- current_row: int
273
- status: str
274
- message: str
275
- max_rows: int
276
- ```""", elem_classes=["md-custom", "PublicWordleState"], header_links=True)
277
-
278
- code_WordleRow = gr.Markdown("""
279
- ## `WordleRow`
280
- ```python
281
- @dataclass
282
- class WordleRow:
283
- letters: List[str] = field(
284
- default_factory=lambda: [""] * 5
285
- )
286
- statuses: List[TileStatus] = field(
287
- default_factory=lambda: ["empty"] * 5
288
- )
289
- ```""", elem_classes=["md-custom", "WordleRow"], header_links=True)
290
-
291
- demo.load(None, js=r"""function() {
292
- const refs = {
293
- PublicWordleState: ['WordleRow'],
294
- WordleRow: [], };
295
- const user_fn_refs = {
296
- WordleBoard: ['PublicWordleState'], };
297
- requestAnimationFrame(() => {
298
-
299
- Object.entries(user_fn_refs).forEach(([key, refs]) => {
300
- if (refs.length > 0) {
301
- const el = document.querySelector(`.${key}-user-fn`);
302
- if (!el) return;
303
- refs.forEach(ref => {
304
- el.innerHTML = el.innerHTML.replace(
305
- new RegExp("\\b"+ref+"\\b", "g"),
306
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
307
- );
308
- })
309
- }
310
- })
311
-
312
- Object.entries(refs).forEach(([key, refs]) => {
313
- if (refs.length > 0) {
314
- const el = document.querySelector(`.${key}`);
315
- if (!el) return;
316
- refs.forEach(ref => {
317
- el.innerHTML = el.innerHTML.replace(
318
- new RegExp("\\b"+ref+"\\b", "g"),
319
- `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
320
- );
321
- })
322
- }
323
- })
324
- })
325
- }
326
-
327
- """)
328
-
329
- demo.launch()
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from __future__ import annotations
3
 
4
  import asyncio
 
119
  raise RuntimeError("HF_TOKEN or API_KEY environment variable must be set.")
120
 
121
  client = AsyncOpenAI(base_url=API_BASE_URL, api_key=api_key)
122
+ env = TextArenaEnv(base_url="https://burtenshaw-textarena.hf.space")
 
 
 
 
 
 
 
123
 
124
  try:
125
  async for result in _play_wordle(env, client):
 
170
  raise SystemExit("HF_TOKEN (or API_KEY) must be set to query the model.")
171
 
172
  demo.launch()