Spaces:
Running
Running
Commit
·
2e9d7fb
1
Parent(s):
f1bae18
added username and password
Browse files
app.py
CHANGED
@@ -4,7 +4,10 @@ import gradio as gr
|
|
4 |
from typing import Any, Callable
|
5 |
import contextvars
|
6 |
from uw_programmatic.uw_machine import UWMachine
|
|
|
|
|
7 |
|
|
|
8 |
|
9 |
def run_with_context(func: Callable) -> Callable:
|
10 |
ctx = contextvars.copy_context()
|
@@ -17,7 +20,7 @@ def run_with_context(func: Callable) -> Callable:
|
|
17 |
|
18 |
def generate_questions(
|
19 |
page_lower, page_higher, question_number, taxonomy
|
20 |
-
) -> tuple[str, dict[str, Any]]:
|
21 |
if machine.value and machine.value.current_state_value == "start":
|
22 |
machine.value.start_machine() # Start the machine!
|
23 |
if not question_number or question_number <= 0:
|
@@ -63,6 +66,9 @@ def generate_questions(
|
|
63 |
gr.update(
|
64 |
visible=True, value=f"{Path.cwd().joinpath('outputs/professor_guide.xlsx')}"
|
65 |
),
|
|
|
|
|
|
|
66 |
)
|
67 |
|
68 |
|
@@ -74,6 +80,9 @@ def create_statemachine() -> None:
|
|
74 |
machine.value = UWMachine.from_config_file(config_path)
|
75 |
except Exception as e:
|
76 |
raise gr.Error(str(e)) from e
|
|
|
|
|
|
|
77 |
|
78 |
|
79 |
with gr.Blocks() as demo:
|
@@ -108,7 +117,17 @@ with gr.Blocks() as demo:
|
|
108 |
start_button.click(
|
109 |
fn=run_with_context(generate_questions),
|
110 |
inputs=[page_lower, page_higher, question_number, taxonomy],
|
111 |
-
outputs=[output, download_professor],
|
|
|
|
|
|
|
|
|
112 |
)
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from typing import Any, Callable
|
5 |
import contextvars
|
6 |
from uw_programmatic.uw_machine import UWMachine
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
import os
|
9 |
|
10 |
+
load_dotenv()
|
11 |
|
12 |
def run_with_context(func: Callable) -> Callable:
|
13 |
ctx = contextvars.copy_context()
|
|
|
20 |
|
21 |
def generate_questions(
|
22 |
page_lower, page_higher, question_number, taxonomy
|
23 |
+
) -> tuple[str, dict[str, Any],dict[str, Any]]:
|
24 |
if machine.value and machine.value.current_state_value == "start":
|
25 |
machine.value.start_machine() # Start the machine!
|
26 |
if not question_number or question_number <= 0:
|
|
|
66 |
gr.update(
|
67 |
visible=True, value=f"{Path.cwd().joinpath('outputs/professor_guide.xlsx')}"
|
68 |
),
|
69 |
+
gr.update(
|
70 |
+
interactive=False
|
71 |
+
)
|
72 |
)
|
73 |
|
74 |
|
|
|
80 |
machine.value = UWMachine.from_config_file(config_path)
|
81 |
except Exception as e:
|
82 |
raise gr.Error(str(e)) from e
|
83 |
+
|
84 |
+
def questions_downloaded() -> dict[str,Any]:
|
85 |
+
return gr.update(interactive=True)
|
86 |
|
87 |
|
88 |
with gr.Blocks() as demo:
|
|
|
117 |
start_button.click(
|
118 |
fn=run_with_context(generate_questions),
|
119 |
inputs=[page_lower, page_higher, question_number, taxonomy],
|
120 |
+
outputs=[output, download_professor, start_button],
|
121 |
+
)
|
122 |
+
download_professor.click(
|
123 |
+
fn=run_with_context(questions_downloaded),
|
124 |
+
outputs=[start_button]
|
125 |
)
|
126 |
+
username = os.getenv('HF_USERNAME','')
|
127 |
+
password = os.getenv('HF_PASSWORD','')
|
128 |
+
if username != '' and password != '':
|
129 |
+
demo.launch(auth=(username,password))
|
130 |
+
else:
|
131 |
+
with gr.Blocks() as failed:
|
132 |
+
gr.Markdown("Environment Error - No username and password provided")
|
133 |
+
failed.launch()
|