qiqiWav commited on
Commit
4da735c
·
verified ·
1 Parent(s): c413227

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -26,18 +26,11 @@ def update_table(category):
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 ""
32
  return f"Hello {profile.username}"
33
 
34
- def update_vote_ui(profile: gr.OAuthProfile | None):
35
- username = get_user(profile)
36
- if username:
37
- username_widget = gr.Textbox(value=username, label="Username", interactive=False)
38
- else:
39
- username_widget = gr.LoginButton()
40
- return username_widget
41
 
42
 
43
  def submit_vote(username, category, vote):
@@ -100,13 +93,16 @@ with gr.Blocks() as app:
100
  category.change(update_table, inputs=category, outputs=table)
101
 
102
  with gr.TabItem("Vote"):
103
- profile = None
104
- if profile:
105
- username = get_user(profile)
106
- username_text = gr.Textbox(value=username, label="Username", interactive=False)
107
- else:
108
- login_button = gr.LoginButton()
 
109
 
 
 
110
  category = gr.Dropdown(
111
  choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
112
  label="Select Category"
@@ -114,7 +110,7 @@ with gr.Blocks() as app:
114
  vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your options")
115
  submit_button = gr.Button("Submit Vote")
116
  submit_result = gr.Label()
117
- if profile:
118
  submit_button.click(fn=submit_vote, inputs=[username_text, category, vote], outputs=submit_result)
119
  else:
120
  submit_button.click(fn=lambda: "Please log in to submit your vote.", inputs=[], outputs=submit_result)
 
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 f"Hello {profile.username}"
33
 
 
 
 
 
 
 
 
34
 
35
 
36
  def submit_vote(username, category, vote):
 
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
+ username_text = gr.Textbox(label="Username", interactive=False, value="Please login")
105
+ gr.LoginButton()
106
  category = gr.Dropdown(
107
  choices=["Biology", "Physics", "Business", "Chemistry", "Economics", "Philosophy", "History", "Culture", "Computer Science", "Math", "Health", "Law", "Engineering", "Other"],
108
  label="Select Category"
 
110
  vote = gr.CheckboxGroup(choices=["Option 1", "Option 2", "Option 3"], label="Choose your options")
111
  submit_button = gr.Button("Submit Vote")
112
  submit_result = gr.Label()
113
+ if username_text:
114
  submit_button.click(fn=submit_vote, inputs=[username_text, category, vote], outputs=submit_result)
115
  else:
116
  submit_button.click(fn=lambda: "Please log in to submit your vote.", inputs=[], outputs=submit_result)