File size: 6,370 Bytes
10f1481
 
 
 
 
 
b1e958e
10f1481
 
 
d4b3c47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10f1481
 
 
 
 
 
 
 
 
87c50d8
10f1481
 
 
 
 
 
 
87c50d8
10f1481
87c50d8
10f1481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87c50d8
10f1481
 
 
 
 
 
 
 
87c50d8
 
10f1481
 
 
 
 
 
 
 
 
 
 
 
 
87c50d8
 
 
 
 
10f1481
 
87c50d8
10f1481
87c50d8
 
 
 
10f1481
 
 
87c50d8
10f1481
 
87c50d8
011869e
4b5a982
011869e
aa25dc5
011869e
 
10f1481
 
87c50d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import gradio as gr
import requests
import time
import os
from dotenv import load_dotenv
from huggingface_hub import list_models
import ast

load_dotenv()
API_URL = os.getenv("API_URL")
choices = [
    "AI/ML",
    "Medical",
    "Legal",
    "Technology",
    "Engineering",
    "Finance",
    "Education",
    "Arts",
    "Marketing",
    "Human Resources",
    "Sales",
    "Manufacturing",
    "Construction",
    "Healthcare",
    "Environmental Science",
    "Data Science",
    "Social Sciences",
    "Psychology",
    "Philosophy",
    "Literature",
    "History",
    "Political Science",
    "Economics",
    "Journalism",
    "Entertainment",
    "Music",
    "Sports",
    "Culinary",
    "Tourism",
    "Logistics",
    "Real Estate",
    "Architecture",
    "Agriculture",
    "Biotechnology",
    "Chemistry",
    "Physics",
    "Mathematics",
    "Astronomy",
    "Geology",
    "Oceanography",
    "Anthropology",
    "Sociology",
    "Linguistics",
    "Religion",
    "Public Administration",
    "Non-profit",
    "Veterinary Science",
    "Library Science",
    "Cybersecurity",
    "Game Development",
    "Robotics",
    "Nanotechnology",
    "Genomics",
    "Telecommunications",
    "Automotive",
    "Energy",
    "Fashion"
]

def check_active_users():
    response = requests.get(f"{API_URL}/status")
    if response.status_code == 200:
        queue_length = response.json().get("queue_length", 0)
        if queue_length > 2:
            return False, "There's currently a high volume of requests. The server is busy processing these requests. Please try again later."
    return True, ""

def process_ui_image(image, user_task, background, purpose, progress=gr.Progress()):
    progress(0)
    
    # Check the number of active users
    can_proceed, message = check_active_users()
    if not can_proceed:
        return message
    
    # Upload image, user task, and field to the API
    files = {'image': open(image, 'rb')}
    data = {'user_task': user_task, 'background': background, 'purpose': purpose}
    response = requests.post(f"{API_URL}/process", files=files, data=data)
    
    if response.status_code != 200:
        return f"Error: {response.text}"
    
    # Get the request ID from the response
    request_id = response.json().get("request_id")
    
    if not request_id:
        return "Error: Failed to get request ID from the server."
    
    # Poll the status of the request
    i = 0.01
    while True:
        status_response = requests.get(f"{API_URL}/status/{request_id}")
        status = status_response.json()
        
        if status.get("status") == "completed":
            progress(1)
            break
        elif status.get("status") == "failed":
            return "Error: Processing failed."

        progress(i)
        i += 0.01
        if i >= 0.9:
            i = 0.9
        time.sleep(1)
    
    # Download the final PDF
    final_pdf_response = requests.get(f"{API_URL}/get_file/{request_id}")
    
    if final_pdf_response.status_code == 200:
        with open("UXEva_report.pdf", "wb") as f:
            f.write(final_pdf_response.content)
        return "UXEva_report.pdf"
    else:
        return "Error: Failed to download the PDF."

def update_submit_button(image, user_task, background, purpose):
    if not image or not user_task or not background or not purpose:
        return gr.update(interactive=False), gr.update(visible=True)
    return gr.update(interactive=True), gr.update(visible=False)

with gr.Blocks(css="""
    .image-preview img {max-height: 400px; max-width: 400px;}
    .disabled {cursor: not-allowed; color: red;}
""") as demo:
    gr.Markdown("""
    <h1 style="text-align: center;">
        <span style="color: green;">UXEva</span>: UI/UX Evaluation Tool Powered by LLM Agent
    </h1>
    """)
    
    with gr.Column(visible=True) as main_ui:
        image_input = gr.Image(type="filepath", label="Upload Image of the UI you want to evaluate", elem_classes="image-preview")
        user_task_input = gr.Textbox(label="Enter the task that user will perform with your UI")
        purposeQ = gr.Dropdown(choices=["Personal Project", "Research", "Professional work", "Student"], label="How are you using this tool?")
        backgroundQ = gr.Dropdown(choices=choices + ["Other"], label="Enter your Background.")
        pdf_output = gr.File(label="Download PDF Report")
        submit_btn = gr.Button("Submit", interactive=False)
        warning = gr.Markdown("<span class='disabled'>Please upload image, enter user task, background, and answer question</span>", visible=False)
    
    image_input.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
    user_task_input.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
    backgroundQ.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
    purposeQ.change(update_submit_button, inputs=[image_input, user_task_input, backgroundQ, purposeQ], outputs=[submit_btn, warning])
    
    submit_btn.click(
        process_ui_image, 
        inputs=[image_input, user_task_input, backgroundQ, purposeQ], 
        outputs=[pdf_output]
    )
    
    gr.Markdown("""
    <h2>Terms of use</h2>
    <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>
    <p>Please note that the insights and recommendations offered in this report are intended for informational and motivational purposes only. We do not warrant the accuracy, completeness, or reliability of the results and take no responsibility for any decisions made based on this report. Users are encouraged to use their judgment and consult with professional UX researchers for comprehensive evaluations. We do not use any users' data to train any model.</p>
    <p>By using this report, you acknowledge and agree that we, as researchers, shall not be held liable for any errors, omissions, or any losses or damages resulting from the use or reliance on the information contained herein.</p>
    """)

demo.queue(default_concurrency_limit=1, max_size=7)
demo.launch()