Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from flask import Flask, redirect, url_for, session, request
|
4 |
-
from requests_oauthlib import OAuth2Session
|
5 |
import os
|
6 |
import time
|
7 |
import re
|
@@ -459,7 +457,7 @@ def show_map_if_details(history,choice):
|
|
459 |
if choice in ["Details", "Conversational"]:
|
460 |
return gr.update(visible=True), update_map_with_response(history)
|
461 |
else:
|
462 |
-
return gr.update(visible
|
463 |
|
464 |
def generate_audio_elevenlabs(text):
|
465 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
@@ -515,93 +513,59 @@ def update_images():
|
|
515 |
image_3 = generate_image(hardcoded_prompt_3)
|
516 |
return image_1, image_2, image_3
|
517 |
|
518 |
-
# Google OAuth2 settings
|
519 |
-
client_id = os.getenv("GOOGLE_CLIENT_ID")
|
520 |
-
client_secret = os.getenv("GOOGLE_CLIENT_SECRET")
|
521 |
-
authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
|
522 |
-
token_url = 'https://accounts.google.com/o/oauth2/token'
|
523 |
-
redirect_uri = 'https://huggingface.co/spaces/Pijush2023/omaha062028v3'
|
524 |
-
|
525 |
-
scope = [
|
526 |
-
"https://www.googleapis.com/auth/userinfo.profile",
|
527 |
-
"https://www.googleapis.com/auth/userinfo.email",
|
528 |
-
"openid",
|
529 |
-
]
|
530 |
-
user_info = {}
|
531 |
-
|
532 |
-
def login():
|
533 |
-
google = OAuth2Session(client_id, scope=scope, redirect_uri=redirect_uri)
|
534 |
-
authorization_url, state = google.authorization_url(authorization_base_url, access_type="offline")
|
535 |
-
user_info['oauth_state'] = state
|
536 |
-
return authorization_url
|
537 |
-
|
538 |
-
def callback(params):
|
539 |
-
global user_info
|
540 |
-
parsed_url = urlparse(params)
|
541 |
-
query_params = parse_qs(parsed_url.query)
|
542 |
-
state = query_params.get('state', [None])[0]
|
543 |
-
if state != user_info.get('oauth_state'):
|
544 |
-
return "Invalid state parameter"
|
545 |
-
|
546 |
-
google = OAuth2Session(client_id, redirect_uri=redirect_uri, state=state)
|
547 |
-
token = google.fetch_token(token_url, client_secret=client_secret, authorization_response=params)
|
548 |
-
user_info.update(google.get('https://www.googleapis.com/oauth2/v1/userinfo').json())
|
549 |
-
user_info['authenticated'] = True
|
550 |
-
return f"Hello {user_info['name']}! You have successfully logged in."
|
551 |
-
|
552 |
def create_gradio_interface():
|
553 |
def greet(name):
|
554 |
return f"Hello {name}, welcome to the Gradio app!"
|
555 |
|
|
|
|
|
|
|
556 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
|
|
595 |
|
596 |
return demo
|
597 |
|
598 |
def main(params=None):
|
599 |
-
if params:
|
600 |
-
callback(params)
|
601 |
demo = create_gradio_interface()
|
602 |
demo.launch()
|
603 |
|
604 |
if __name__ == "__main__":
|
605 |
-
|
606 |
-
params = sys.argv[1] if len(sys.argv) > 1 else None
|
607 |
-
main(params)
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
3 |
import os
|
4 |
import time
|
5 |
import re
|
|
|
457 |
if choice in ["Details", "Conversational"]:
|
458 |
return gr.update(visible=True), update_map_with_response(history)
|
459 |
else:
|
460 |
+
return gr.update(visible=False), ""
|
461 |
|
462 |
def generate_audio_elevenlabs(text):
|
463 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
|
|
513 |
image_3 = generate_image(hardcoded_prompt_3)
|
514 |
return image_1, image_2, image_3
|
515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
def create_gradio_interface():
|
517 |
def greet(name):
|
518 |
return f"Hello {name}, welcome to the Gradio app!"
|
519 |
|
520 |
+
def login_button_click():
|
521 |
+
return "Login clicked! (Implement login functionality here)"
|
522 |
+
|
523 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
524 |
+
gr.Markdown("<div style='text-align: right;'><button class='gr-button gr-button-primary' id='login-button'>Login with Google</button></div>")
|
525 |
+
gr.Markdown(f"### Hello, User! Welcome to the Gradio App")
|
526 |
+
|
527 |
+
name = gr.Textbox(label="Enter your name")
|
528 |
+
greet_btn = gr.Button("Greet")
|
529 |
+
output = gr.Textbox(label="Greeting")
|
530 |
+
greet_btn.click(greet, inputs=name, outputs=output)
|
531 |
+
|
532 |
+
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
533 |
+
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
534 |
+
|
535 |
+
gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
536 |
+
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
|
537 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
538 |
+
bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
|
539 |
+
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
|
540 |
+
chatbot.like(print_like_dislike, None, None)
|
541 |
+
clear_button = gr.Button("Clear")
|
542 |
+
clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
|
543 |
+
|
544 |
+
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
|
545 |
+
audio_input.stream(transcribe_function, inputs=[audio_input], outputs=[chat_input], api_name="SAMLOne_real_time")
|
546 |
+
|
547 |
+
gr.Markdown("<h1 style='color: red;'>Map</h1>", elem_id="location-markdown")
|
548 |
+
location_output = gr.HTML()
|
549 |
+
bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
|
550 |
+
|
551 |
+
weather_output = gr.HTML(value=fetch_local_weather())
|
552 |
+
news_output = gr.HTML(value=fetch_local_news())
|
553 |
+
events_output = gr.HTML(value=fetch_local_events())
|
554 |
+
|
555 |
+
image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
|
556 |
+
image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
|
557 |
+
image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
|
558 |
+
refresh_button = gr.Button("Refresh Images")
|
559 |
+
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
560 |
+
|
561 |
+
login_button = gr.Button("Login with Google", elem_id="login-button")
|
562 |
+
login_button.click(login_button_click, inputs=[], outputs=[])
|
563 |
|
564 |
return demo
|
565 |
|
566 |
def main(params=None):
|
|
|
|
|
567 |
demo = create_gradio_interface()
|
568 |
demo.launch()
|
569 |
|
570 |
if __name__ == "__main__":
|
571 |
+
main()
|
|
|
|