jy-raychen commited on
Commit
96ba60d
·
verified ·
1 Parent(s): c666af5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -3
app.py CHANGED
@@ -1,7 +1,105 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
 
 
 
3
 
4
+ # --- Init params ---
5
+ def init_params(text, request: gr.Request):
6
+ if request:
7
+ print("Request headers dictionary:", request.headers)
8
+ print("IP address:", request.client.host)
9
+ print("Query parameters:", dict(request.query_params))
10
+ # url = request.url
11
+ print("Request URL:", request.url)
12
+
13
+ youtube_link = ""
14
+ password_text = ""
15
+ admin = gr.update(visible=True)
16
+ reading_passage_admin = gr.update(visible=True)
17
+ summary_admin = gr.update(visible=True)
18
+ see_detail = gr.update(visible=True)
19
+ worksheet_accordion = gr.update(visible=True)
20
+ lesson_plan_accordion = gr.update(visible=True)
21
+ exit_ticket_accordion = gr.update(visible=True)
22
+
23
+ chatbot_open_ai_streaming = gr.update(visible=False)
24
+ chatbot_ai = gr.update(visible=False)
25
+ ai_chatbot_params = gr.update(visible=True)
26
+
27
+ is_env_prod = gr.update(value=False)
28
+
29
+ # if youtube_link in query_params
30
+ if "youtube_id" in request.query_params:
31
+ youtube_id = request.query_params["youtube_id"]
32
+ youtube_link = f"https://www.youtube.com/watch?v={youtube_id}"
33
+ print(f"youtube_link: {youtube_link}")
34
+
35
+ # check if origin is from junyiacademy
36
+ origin = request.headers.get("origin", "")
37
+ if "junyiacademy" in origin:
38
+ password_text = PASSWORD
39
+ admin = gr.update(visible=False)
40
+ reading_passage_admin = gr.update(visible=False)
41
+ summary_admin = gr.update(visible=False)
42
+ see_detail = gr.update(visible=False)
43
+ worksheet_accordion = gr.update(visible=False)
44
+ lesson_plan_accordion = gr.update(visible=False)
45
+ exit_ticket_accordion = gr.update(visible=False)
46
+ ai_chatbot_params = gr.update(visible=False)
47
+
48
+ if IS_ENV_PROD == "True":
49
+ is_env_prod = gr.update(value=True)
50
+
51
+ return admin, reading_passage_admin, summary_admin, see_detail, \
52
+ worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
53
+ password_text, youtube_link, \
54
+ chatbot_open_ai_streaming, chatbot_ai, ai_chatbot_params, \
55
+ is_env_prod
56
+
57
+ HEAD = """
58
+ <meta charset="UTF-8">
59
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
60
+ <style>
61
+ svg.markmap {{
62
+ width: 100%;
63
+ height: 100vh;
64
+ }}
65
+ </style>
66
+ <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader@0.15.2"></script>
67
+ <script>
68
+ const mind_map_tab_button = document.querySelector("#mind_map_tab-button");
69
+
70
+ if (mind_map_tab_button) {
71
+ mind_map_tab_button.addEventListener('click', function() {
72
+ const mind_map_markdown = document.querySelector("#mind_map_markdown > label > textarea");
73
+ if (mind_map_markdown) {
74
+ // 当按钮被点击时,打印当前的textarea的值
75
+ console.log('Value changed to: ' + mind_map_markdown.value);
76
+ markmap.autoLoader.renderAll();
77
+ }
78
+ });
79
+ }
80
+ </script>
81
+ """
82
+
83
+ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.amber, text_size = gr.themes.sizes.text_lg), head=HEAD) as demo:
84
+ with gr.Row() as admin:
85
+ password = gr.Textbox(label="Password", type="password", elem_id="password_input", visible=True)
86
+ youtube_link = gr.Textbox(label="Enter YouTube Link", elem_id="youtube_link_input", visible=True)
87
+ video_id = gr.Textbox(label="video_id", visible=True)
88
+ # file_upload = gr.File(label="Upload your CSV or Word file", visible=False)
89
+ # web_link = gr.Textbox(label="Enter Web Page Link", visible=False)
90
+ user_data = gr.Textbox(label="User Data", elem_id="user_data_input", visible=True)
91
+ youtube_link_btn = gr.Button("Submit_YouTube_Link", elem_id="youtube_link_btn", visible=True)
92
+
93
+
94
+ # init_params
95
+ init_outputs = [
96
+ admin,
97
+ password,
98
+ youtube_link,
99
+ ]
100
+ demo.load(
101
+ init_params,
102
+ inputs =[youtube_link],
103
+ outputs = init_outputs
104
+ )
105
  demo.launch()