Spaces:
Sleeping
Sleeping
allowed_request_origins = [
Browse files
app.py
CHANGED
@@ -664,9 +664,19 @@ def init_params(request: gr.Request):
|
|
664 |
|
665 |
# check if origin is from junyiacademy
|
666 |
query_params = dict(request.query_params)
|
667 |
-
|
668 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
pass
|
|
|
|
|
670 |
|
671 |
if "language" in query_params:
|
672 |
if query_params["language"] == "english":
|
@@ -679,17 +689,9 @@ def init_params(request: gr.Request):
|
|
679 |
chinese_group = gr.update(visible=True)
|
680 |
|
681 |
|
682 |
-
return english_group, chinese_group
|
683 |
|
684 |
def update_english_grapragh_practice_rows(selected_tab):
|
685 |
-
# outputs=[
|
686 |
-
# english_grapragh_practice_row,
|
687 |
-
# english_grapragh_evaluate_row,
|
688 |
-
# english_exam_practice_row,
|
689 |
-
# english_grapragh_practice_button,
|
690 |
-
# english_grapragh_evaluate_button,
|
691 |
-
# english_exam_practice_tab_button
|
692 |
-
# ]
|
693 |
if selected_tab == "📝 英文段落寫作練習":
|
694 |
gr_update_english_grapragh_practice_row = gr.update(visible=True)
|
695 |
gr_update_english_grapragh_evaluate_row = gr.update(visible=False)
|
@@ -768,6 +770,10 @@ english_exam_practice_tab_button_js = """
|
|
768 |
|
769 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.orange), css=CSS) as demo:
|
770 |
|
|
|
|
|
|
|
|
|
771 |
with gr.Row(visible=False) as english_group:
|
772 |
with gr.Column():
|
773 |
with gr.Row() as page_title_english:
|
@@ -2121,6 +2127,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
2121 |
init_params,
|
2122 |
inputs =[],
|
2123 |
outputs = [
|
|
|
2124 |
english_group,
|
2125 |
chinese_group
|
2126 |
]
|
|
|
664 |
|
665 |
# check if origin is from junyiacademy
|
666 |
query_params = dict(request.query_params)
|
667 |
+
request_origin = request.headers.get("origin", "").replace("https://", "").replace("http://", "")
|
668 |
+
print(f"request_origin: {request_origin}")
|
669 |
+
allowed_request_origins = [
|
670 |
+
"junyiacademy.org",
|
671 |
+
"junyiacademy.appspot.com",
|
672 |
+
"colearn30.com", # 樂寫網
|
673 |
+
"huggingface.co",
|
674 |
+
"localhost:7860"
|
675 |
+
]
|
676 |
+
if any(allowed_origin in request_origin for allowed_origin in allowed_request_origins):
|
677 |
pass
|
678 |
+
else:
|
679 |
+
raise gr.Error("Invalid origin")
|
680 |
|
681 |
if "language" in query_params:
|
682 |
if query_params["language"] == "english":
|
|
|
689 |
chinese_group = gr.update(visible=True)
|
690 |
|
691 |
|
692 |
+
return request_origin, english_group, chinese_group
|
693 |
|
694 |
def update_english_grapragh_practice_rows(selected_tab):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
695 |
if selected_tab == "📝 英文段落寫作練習":
|
696 |
gr_update_english_grapragh_practice_row = gr.update(visible=True)
|
697 |
gr_update_english_grapragh_evaluate_row = gr.update(visible=False)
|
|
|
770 |
|
771 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.orange), css=CSS) as demo:
|
772 |
|
773 |
+
with gr.Row(visible=True) as admin_group:
|
774 |
+
user_data = gr.Textbox(label="User Data", value="")
|
775 |
+
request_origin = gr.Textbox(label="Request Domain", value="")
|
776 |
+
|
777 |
with gr.Row(visible=False) as english_group:
|
778 |
with gr.Column():
|
779 |
with gr.Row() as page_title_english:
|
|
|
2127 |
init_params,
|
2128 |
inputs =[],
|
2129 |
outputs = [
|
2130 |
+
request_origin,
|
2131 |
english_group,
|
2132 |
chinese_group
|
2133 |
]
|