Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,13 +7,7 @@ from huggingface_hub import list_models
|
|
7 |
|
8 |
load_dotenv()
|
9 |
API_URL = os.getenv("API_URL")
|
10 |
-
|
11 |
-
def __init__(self, _id=None):
|
12 |
-
self._id = _id
|
13 |
-
self.name = ""
|
14 |
-
self.username = ""
|
15 |
-
|
16 |
-
newprofile = CreateProfile()
|
17 |
|
18 |
def check_active_users():
|
19 |
response = requests.get(f"{API_URL}/status")
|
@@ -23,7 +17,7 @@ def check_active_users():
|
|
23 |
return False, "There's currently a high volume of requests. The server is busy processing these requests. Please try again later."
|
24 |
return True, ""
|
25 |
|
26 |
-
def process_ui_image(image, user_task, progress=gr.Progress()):
|
27 |
progress(0)
|
28 |
|
29 |
# Check the number of active users
|
@@ -31,9 +25,9 @@ def process_ui_image(image, user_task, progress=gr.Progress()):
|
|
31 |
if not can_proceed:
|
32 |
return message
|
33 |
|
34 |
-
# Upload image
|
35 |
files = {'image': open(image, 'rb')}
|
36 |
-
data = {'user_task': user_task,
|
37 |
response = requests.post(f"{API_URL}/process", files=files, data=data)
|
38 |
|
39 |
if response.status_code != 200:
|
@@ -41,7 +35,6 @@ def process_ui_image(image, user_task, progress=gr.Progress()):
|
|
41 |
|
42 |
# Get the request ID from the response
|
43 |
request_id = response.json().get("request_id")
|
44 |
-
|
45 |
|
46 |
if not request_id:
|
47 |
return "Error: Failed to get request ID from the server."
|
@@ -65,7 +58,7 @@ def process_ui_image(image, user_task, progress=gr.Progress()):
|
|
65 |
time.sleep(1)
|
66 |
|
67 |
# Download the final PDF
|
68 |
-
final_pdf_response = requests.get(f"{API_URL}/get_file")
|
69 |
|
70 |
if final_pdf_response.status_code == 200:
|
71 |
with open("UXEva_report.pdf", "wb") as f:
|
@@ -74,12 +67,11 @@ def process_ui_image(image, user_task, progress=gr.Progress()):
|
|
74 |
else:
|
75 |
return "Error: Failed to download the PDF."
|
76 |
|
77 |
-
def update_submit_button(image, user_task):
|
78 |
-
if not image or not user_task:
|
79 |
return gr.update(interactive=False), gr.update(visible=True)
|
80 |
return gr.update(interactive=True), gr.update(visible=False)
|
81 |
|
82 |
-
|
83 |
with gr.Blocks(css="""
|
84 |
.image-preview img {max-height: 400px; max-width: 400px;}
|
85 |
.disabled {cursor: not-allowed; color: red;}
|
@@ -89,33 +81,27 @@ with gr.Blocks(css="""
|
|
89 |
<span style="color: green;">UXEva</span>: UI/UX Evaluation Tool Powered by LLM Agent
|
90 |
</h1>
|
91 |
""")
|
92 |
-
gr.LoginButton()
|
93 |
|
94 |
-
with gr.Column(visible=
|
95 |
-
image_input = gr.Image(type="filepath", label="Upload UI
|
96 |
-
user_task_input = gr.Textbox(label="Enter
|
|
|
|
|
97 |
pdf_output = gr.File(label="Download PDF Report")
|
98 |
submit_btn = gr.Button("Submit", interactive=False)
|
99 |
-
warning = gr.Markdown("<span class='disabled'>
|
100 |
|
101 |
-
image_input.change(update_submit_button, inputs=[image_input, user_task_input], outputs=[submit_btn, warning])
|
102 |
-
user_task_input.change(update_submit_button, inputs=[image_input, user_task_input], outputs=[submit_btn, warning])
|
|
|
|
|
103 |
|
104 |
submit_btn.click(
|
105 |
process_ui_image,
|
106 |
-
inputs=[image_input, user_task_input],
|
107 |
outputs=[pdf_output]
|
108 |
)
|
109 |
-
|
110 |
-
global newprofile
|
111 |
-
if profile is None:
|
112 |
-
print("unknow user.")
|
113 |
-
else:
|
114 |
-
newprofile.name = profile.name
|
115 |
-
newprofile.username = profile.username
|
116 |
-
return {main_ui: gr.Column(visible=True)}
|
117 |
-
|
118 |
-
demo.load(get_profile, inputs=None, outputs=[main_ui])
|
119 |
gr.Markdown("""
|
120 |
<h2>Terms of use</h2>
|
121 |
<p>The UI Analysis Report provided herein has been generated by an LLM-powered agent designed to assist individuals, researchers, startups, and companies in conducting UI evaluations and enhancing the efficiency of UX researchers.</p>
|
@@ -124,4 +110,4 @@ with gr.Blocks(css="""
|
|
124 |
""")
|
125 |
|
126 |
demo.queue(default_concurrency_limit=1, max_size=7)
|
127 |
-
demo.launch()
|
|
|
7 |
|
8 |
load_dotenv()
|
9 |
API_URL = os.getenv("API_URL")
|
10 |
+
choices = os.getenv("choices")
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def check_active_users():
|
13 |
response = requests.get(f"{API_URL}/status")
|
|
|
17 |
return False, "There's currently a high volume of requests. The server is busy processing these requests. Please try again later."
|
18 |
return True, ""
|
19 |
|
20 |
+
def process_ui_image(image, user_task, background, purpose, progress=gr.Progress()):
|
21 |
progress(0)
|
22 |
|
23 |
# Check the number of active users
|
|
|
25 |
if not can_proceed:
|
26 |
return message
|
27 |
|
28 |
+
# Upload image, user task, and field to the API
|
29 |
files = {'image': open(image, 'rb')}
|
30 |
+
data = {'user_task': user_task, 'background': background, 'purpose': purpose}
|
31 |
response = requests.post(f"{API_URL}/process", files=files, data=data)
|
32 |
|
33 |
if response.status_code != 200:
|
|
|
35 |
|
36 |
# Get the request ID from the response
|
37 |
request_id = response.json().get("request_id")
|
|
|
38 |
|
39 |
if not request_id:
|
40 |
return "Error: Failed to get request ID from the server."
|
|
|
58 |
time.sleep(1)
|
59 |
|
60 |
# Download the final PDF
|
61 |
+
final_pdf_response = requests.get(f"{API_URL}/get_file/{request_id}")
|
62 |
|
63 |
if final_pdf_response.status_code == 200:
|
64 |
with open("UXEva_report.pdf", "wb") as f:
|
|
|
67 |
else:
|
68 |
return "Error: Failed to download the PDF."
|
69 |
|
70 |
+
def update_submit_button(image, user_task, background, purpose):
|
71 |
+
if not image or not user_task or not background or not purpose:
|
72 |
return gr.update(interactive=False), gr.update(visible=True)
|
73 |
return gr.update(interactive=True), gr.update(visible=False)
|
74 |
|
|
|
75 |
with gr.Blocks(css="""
|
76 |
.image-preview img {max-height: 400px; max-width: 400px;}
|
77 |
.disabled {cursor: not-allowed; color: red;}
|
|
|
81 |
<span style="color: green;">UXEva</span>: UI/UX Evaluation Tool Powered by LLM Agent
|
82 |
</h1>
|
83 |
""")
|
|
|
84 |
|
85 |
+
with gr.Column(visible=True) as main_ui:
|
86 |
+
image_input = gr.Image(type="filepath", label="Upload Image of the UI you want to evaluate", elem_classes="image-preview")
|
87 |
+
user_task_input = gr.Textbox(label="Enter the task that user will perform with your UI")
|
88 |
+
purposeQ = gr.Dropdown(choices=["Personal Project", "Research", "Professional work", "Student"], label="How are you using this tool?")
|
89 |
+
backgroundQ = gr.Dropdown(choices=choices + ["Other"], label="Enter your Background.")
|
90 |
pdf_output = gr.File(label="Download PDF Report")
|
91 |
submit_btn = gr.Button("Submit", interactive=False)
|
92 |
+
warning = gr.Markdown("<span class='disabled'>Please upload image, enter user task, background, and answer question</span>", visible=False)
|
93 |
|
94 |
+
image_input.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
|
95 |
+
user_task_input.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
|
96 |
+
backgroundQ.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
|
97 |
+
purposeQ.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
|
98 |
|
99 |
submit_btn.click(
|
100 |
process_ui_image,
|
101 |
+
inputs=[image_input, user_task_input, backgroundQ, purposeQ],
|
102 |
outputs=[pdf_output]
|
103 |
)
|
104 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
gr.Markdown("""
|
106 |
<h2>Terms of use</h2>
|
107 |
<p>The UI Analysis Report provided herein has been generated by an LLM-powered agent designed to assist individuals, researchers, startups, and companies in conducting UI evaluations and enhancing the efficiency of UX researchers.</p>
|
|
|
110 |
""")
|
111 |
|
112 |
demo.queue(default_concurrency_limit=1, max_size=7)
|
113 |
+
demo.launch()
|