Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -834,49 +834,94 @@ def update_images():
|
|
834 |
return image_1, image_2, image_3
|
835 |
|
836 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
837 |
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
weather_output = gr.HTML(value=fetch_local_weather())
|
866 |
-
news_output = gr.HTML(value=fetch_local_news())
|
867 |
-
news_output = gr.HTML(value=fetch_local_events())
|
868 |
-
|
869 |
-
with gr.Column():
|
870 |
-
|
871 |
-
image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
|
872 |
-
image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
|
873 |
-
image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
|
874 |
-
|
875 |
-
|
876 |
-
refresh_button = gr.Button("Refresh Images")
|
877 |
-
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
878 |
-
|
879 |
-
demo.queue()
|
880 |
-
demo.launch(share=True)
|
881 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
882 |
|
|
|
834 |
return image_1, image_2, image_3
|
835 |
|
836 |
|
837 |
+
import os
|
838 |
+
import gradio as gr
|
839 |
+
from flask import Flask, redirect, request, url_for, session
|
840 |
+
from authlib.integrations.flask_client import OAuth
|
841 |
+
|
842 |
+
# Flask app setup
|
843 |
+
app = Flask(__name__)
|
844 |
+
app.secret_key = 'RANDOM_SECRET_KEY'
|
845 |
+
app.config['SESSION_COOKIE_NAME'] = 'google-login-session'
|
846 |
+
|
847 |
+
# OAuth setup
|
848 |
+
oauth = OAuth(app)
|
849 |
+
google = oauth.register(
|
850 |
+
name='google',
|
851 |
+
client_id=os.getenv('GOOGLE_CLIENT_ID'),
|
852 |
+
client_secret=os.getenv('GOOGLE_CLIENT_SECRET'),
|
853 |
+
access_token_url='https://accounts.google.com/o/oauth2/token',
|
854 |
+
access_token_params=None,
|
855 |
+
authorize_url='https://accounts.google.com/o/oauth2/auth',
|
856 |
+
authorize_params=None,
|
857 |
+
api_base_url='https://www.googleapis.com/oauth2/v1/',
|
858 |
+
userinfo_endpoint='https://openidconnect.googleapis.com/v1/userinfo',
|
859 |
+
client_kwargs={'scope': 'openid email profile'},
|
860 |
+
)
|
861 |
|
862 |
+
# Define login route
|
863 |
+
@app.route('/login')
|
864 |
+
def login():
|
865 |
+
google = oauth.create_client('google')
|
866 |
+
redirect_uri = url_for('authorize', _external=True)
|
867 |
+
return google.authorize_redirect(redirect_uri)
|
868 |
+
|
869 |
+
# Define authorize route
|
870 |
+
@app.route('/authorize')
|
871 |
+
def authorize():
|
872 |
+
google = oauth.create_client('google')
|
873 |
+
token = google.authorize_access_token()
|
874 |
+
user = google.parse_id_token(token)
|
875 |
+
session['user'] = user
|
876 |
+
return redirect('/')
|
877 |
+
|
878 |
+
# Define logout route
|
879 |
+
@app.route('/logout')
|
880 |
+
def logout():
|
881 |
+
session.pop('user', None)
|
882 |
+
return redirect('/')
|
883 |
+
|
884 |
+
# Define home route
|
885 |
+
@app.route('/')
|
886 |
+
def home():
|
887 |
+
user = dict(session).get('user', None)
|
888 |
+
return f'Hello, {user["name"]}!' if user else 'Hello, you are not logged in!'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
889 |
|
890 |
+
|
891 |
+
# Integrate Gradio with Flask
|
892 |
+
@app.route('/gradio')
|
893 |
+
def gradio_interface():
|
894 |
+
with gr.Blocks() as demo:
|
895 |
+
with gr.Row():
|
896 |
+
with gr.Column():
|
897 |
+
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
898 |
+
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
899 |
+
gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
900 |
+
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
|
901 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
902 |
+
bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
|
903 |
+
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
|
904 |
+
chatbot.like(print_like_dislike, None, None)
|
905 |
+
clear_button = gr.Button("Clear")
|
906 |
+
clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
|
907 |
+
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
|
908 |
+
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="SAMLOne_real_time")
|
909 |
+
gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
|
910 |
+
location_output = gr.HTML()
|
911 |
+
bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
|
912 |
+
with gr.Column():
|
913 |
+
weather_output = gr.HTML(value=fetch_local_weather())
|
914 |
+
news_output = gr.HTML(value=fetch_local_news())
|
915 |
+
news_output = gr.HTML(value=fetch_local_events())
|
916 |
+
with gr.Column():
|
917 |
+
image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
|
918 |
+
image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
|
919 |
+
image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
|
920 |
+
refresh_button = gr.Button("Refresh Images")
|
921 |
+
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
922 |
+
demo.queue()
|
923 |
+
demo.launch(share=True, inline=False, server_name="0.0.0.0", server_port=7860)
|
924 |
+
|
925 |
+
if __name__ == "__main__":
|
926 |
+
app.run(port=5000)
|
927 |
|