qiqiWav commited on
Commit
7786c4d
·
verified ·
1 Parent(s): c146544

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -26,10 +26,10 @@ def update_table(category):
26
  df = pd.DataFrame(data)
27
  return df
28
 
29
- def get_user(profile):
30
  if profile is None:
31
  return "Please log in to see your username."
32
- return {profile.username}
33
 
34
 
35
 
@@ -93,17 +93,9 @@ with gr.Blocks() as app:
93
  category.change(update_table, inputs=category, outputs=table)
94
 
95
  with gr.TabItem("Vote"):
96
- # m1 = gr.Markdown()
97
- # profile = app.load(get_user, inputs=None, outputs=m1)
98
- # if profile:
99
- # username = get_user(profile)
100
- # username_text = gr.Textbox(value=profile, label="Username", interactive=False)
101
- # else:
102
- # login_button = gr.LoginButton()
103
-
104
  login_button = gr.LoginButton()
105
- username_text = gr.Variable(value="Please log in to see your username.") # 这里使用Variable来存储用户名
106
- login_button.output(username_text, fn=get_user)
107
 
108
  category = gr.Dropdown(
109
  choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
@@ -112,7 +104,8 @@ with gr.Blocks() as app:
112
  vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your options")
113
  submit_button = gr.Button("Submit Vote")
114
  submit_result = gr.Label()
115
- submit_button.click(fn=submit_vote, inputs=[username_text, category, votes], outputs=submit_result)
 
116
 
117
 
118
  # with gr.TabItem("Submit Model"):
 
26
  df = pd.DataFrame(data)
27
  return df
28
 
29
+ def get_user(profile: gr.OAuthProfile | None) -> str:
30
  if profile is None:
31
  return "Please log in to see your username."
32
+ return profile.username
33
 
34
 
35
 
 
93
  category.change(update_table, inputs=category, outputs=table)
94
 
95
  with gr.TabItem("Vote"):
96
+ username_text = gr.State(value="")
 
 
 
 
 
 
 
97
  login_button = gr.LoginButton()
98
+ app.load(get_user, inputs=None, outputs=username_text)
 
99
 
100
  category = gr.Dropdown(
101
  choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
 
104
  vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your options")
105
  submit_button = gr.Button("Submit Vote")
106
  submit_result = gr.Label()
107
+
108
+ submit_button.click(fn=submit_vote, inputs=[username_text, category, vote], outputs=submit_result)
109
 
110
 
111
  # with gr.TabItem("Submit Model"):