fhudi commited on
Commit
ceaea42
·
1 Parent(s): 31ea02f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -71
app.py CHANGED
@@ -1,77 +1,10 @@
1
- #%%
2
- import os
3
- # os.environ.setdefault("GRADIO_SERVER_PORT", "1080")
4
- # os.environ.setdefault("TEXTGAMES_SHOW_HIDDEN_LEVEL", "1")
5
- os.environ.setdefault("TEXTGAMES_LOADGAME_DIR", "problemsets")
6
- os.environ.setdefault("TEXTGAMES_LOADGAME_ID", "42")
7
- os.environ.setdefault("TEXTGAMES_MOCKUSER", "")
8
- os.environ.setdefault("TEXTGAMES_OUTPUT_DIR", "user_outputs")
9
- favicon_path = "textgames-scrabble-black2-ss.png"
10
-
11
- #%%
12
- from play_helper import css, declare_components, start_new_game, download_from_drive
13
- import pandas as pd
14
  import gradio as gr
15
 
16
 
17
- #%%
18
- fp_user_auth = f"{os.getenv('TEXTGAMES_OUTPUT_DIR')}/textgames_userauth.tsv"
19
- # fp_user_auth_id = "13RLyxV3ys5DGgRIJt5_tO-ILllJ1LDPGasobagZyVLU"
20
- fp_user_auth_mime_type = "text/tab-separated-values"
21
-
22
-
23
- #%%
24
- def file_based_auth(username, password):
25
- if os.getenv('TEXTGAMES_MOCKUSER', ''):
26
- return True
27
- download_from_drive(fp_user_auth, mime_type=fp_user_auth_mime_type)
28
- df_auth = pd.read_csv(fp_user_auth, sep="\t").dropna(how="any")
29
- return len(df_auth.loc[(df_auth.EMAIL == username) & (df_auth.PASSWORD == password)]) > 0
30
-
31
-
32
- #%%
33
- def greet(request: gr.Request):
34
- email = os.getenv('TEXTGAMES_MOCKUSER', '')
35
- if email:
36
- user = {'email': email, 'name': "mockuser"}
37
- else:
38
- df_auth = pd.read_csv(fp_user_auth, sep="\t").dropna(how="any").drop_duplicates(subset=['EMAIL'])
39
- r = df_auth.loc[df_auth.EMAIL == request.username].iloc[0]
40
- user = {'email': r.EMAIL, 'name': r.NAME}
41
- return f"""
42
- Welcome to TextGames, {user['name']}!<br/><{user['email'].replace('@', '{at}')}>
43
- """, user, user['email']
44
-
45
- # return f"""
46
- # Welcome to TextGames, {user['name']}!<br />
47
- # <{user['email'].replace('@', '{at}')}> ({'' if user['email_verified'] else 'NON-'}verified email)
48
- # """, None, None
49
-
50
-
51
- #%%
52
- with gr.Blocks(title="TextGames", css=css, delete_cache=(3600, 3600)) as demo:
53
- ((m, logout_btn, solved_games_df, game_radio, level_radio, new_game_btn, render_toggle),
54
- (session_state, is_solved, solved_games, user_state, uid_state),
55
- ) = declare_components(demo, greet)
56
-
57
- @gr.render(inputs=[game_radio, level_radio, user_state, session_state, uid_state], triggers=[render_toggle.change])
58
- def _start_new_game(game_name, level, user, _session_state, _uid_state):
59
- if _session_state in [1, 2]:
60
- start_new_game(game_name, level, session_state, is_solved, solved_games, user=user, uid=_uid_state)
61
-
62
- demo.launch(
63
- auth=file_based_auth,
64
- favicon_path=favicon_path if os.path.exists(favicon_path) else None,
65
- # share=True,
66
- )
67
-
68
-
69
- #%%
70
-
71
-
72
- #%%
73
-
74
 
75
- #%%
76
 
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
 
4
+ def greet(name):
5
+ return "Hello " + name + "!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
 
7
 
8
+ demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
9
 
10
+ demo.launch(share=True)