Pijush2023 commited on
Commit
7a0b2af
·
verified ·
1 Parent(s): c96f2fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -49
app.py CHANGED
@@ -945,62 +945,54 @@ def callback(params):
945
  google = OAuth2Session(client_id, redirect_uri=redirect_uri, state=state)
946
  token = google.fetch_token(token_url, client_secret=client_secret, authorization_response=params)
947
  user_info.update(google.get('https://www.googleapis.com/oauth2/v1/userinfo').json())
948
- state['authenticated'] = True
949
- state['user_info'] = user_info
950
  return f"Hello {user_info['name']}! You have successfully logged in."
951
 
952
  def create_gradio_interface():
953
  def greet(name):
954
  return f"Hello {name}, welcome to the Gradio app!"
 
 
955
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
956
- state = gr.State({'authenticated': False, 'user_info': {}})
957
-
958
- # if user_info:
959
- # state.value = {'authenticated': True, 'user_info': user_info}
960
-
961
- def update_interface():
962
- if state.value['authenticated']:
963
- gr.Markdown(f"### Hello, {state.value['user_info']['name']}! Welcome to the Gradio App")
964
- name = gr.Textbox(label="Enter your name")
965
- greet_btn = gr.Button("Greet")
966
- output = gr.Textbox(label="Greeting")
967
- greet_btn.click(greet, inputs=name, outputs=output)
968
-
969
- chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
970
- choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
971
-
972
- gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
973
- chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
974
- chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
975
- bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
976
- bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
977
- chatbot.like(print_like_dislike, None, None)
978
- clear_button = gr.Button("Clear")
979
- clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
980
-
981
- audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
982
- audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
983
-
984
- gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
985
- location_output = gr.HTML()
986
- bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
987
-
988
- weather_output = gr.HTML(value=fetch_local_weather())
989
- news_output = gr.HTML(value=fetch_local_news())
990
- events_output = gr.HTML(value=fetch_local_events())
991
-
992
- image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
993
- image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
994
- image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
995
- refresh_button = gr.Button("Refresh Images")
996
- refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
997
 
998
- else:
999
- login_url = login()
1000
- gr.Markdown(f"<div style='text-align: right;'><a href='{login_url}' class='gr-button gr-button-primary'>Login with Google</a></div>")
1001
-
1002
- update_interface()
1003
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1004
  return demo
1005
 
1006
  def main(params=None):
 
945
  google = OAuth2Session(client_id, redirect_uri=redirect_uri, state=state)
946
  token = google.fetch_token(token_url, client_secret=client_secret, authorization_response=params)
947
  user_info.update(google.get('https://www.googleapis.com/oauth2/v1/userinfo').json())
948
+ user_info['authenticated'] = True
 
949
  return f"Hello {user_info['name']}! You have successfully logged in."
950
 
951
  def create_gradio_interface():
952
  def greet(name):
953
  return f"Hello {name}, welcome to the Gradio app!"
954
+
955
+
956
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
957
+ if user_info.get('authenticated', False):
958
+ gr.Markdown(f"### Hello, {user_info['name']}! Welcome to the Gradio App")
959
+ name = gr.Textbox(label="Enter your name")
960
+ greet_btn = gr.Button("Greet")
961
+ output = gr.Textbox(label="Greeting")
962
+ greet_btn.click(greet, inputs=name, outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
 
964
+ chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
965
+ choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
966
+
967
+ gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
968
+ chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
969
+ chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
970
+ bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
971
+ bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
972
+ chatbot.like(print_like_dislike, None, None)
973
+ clear_button = gr.Button("Clear")
974
+ clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
975
+
976
+ audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
977
+ audio_input.stream(transcribe_function, inputs=[audio_input], outputs=[chat_input], api_name="SAMLOne_real_time")
978
+
979
+ gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
980
+ location_output = gr.HTML()
981
+ bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
982
+
983
+ weather_output = gr.HTML(value=fetch_local_weather())
984
+ news_output = gr.HTML(value=fetch_local_news())
985
+ events_output = gr.HTML(value=fetch_local_events())
986
+
987
+ image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
988
+ image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
989
+ image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
990
+ refresh_button = gr.Button("Refresh Images")
991
+ refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
992
+ else:
993
+ login_url = login()
994
+ gr.Markdown(f"<div style='text-align: right;'><a href='{login_url}' class='gr-button gr-button-primary'>Login with Google</a></div>")
995
+
996
  return demo
997
 
998
  def main(params=None):