UXEva / app.py
AnjaliRai78's picture
Update app.py
aa25dc5 verified
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()