Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,129 +1,46 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
with gr.Blocks() as iface:
|
| 4 |
-
"""
|
| 5 |
-
with gr.Row(visible=False) as app_row:
|
| 6 |
-
with gr.Column():
|
| 7 |
-
with gr.Row():
|
| 8 |
-
with gr.Column(scale=2):
|
| 9 |
-
gr.Image(label="Logo", value="Nili_v2_Character.png", width=100, height=100, show_download_button=False,
|
| 10 |
-
interactive=False, show_label=False, elem_id="logo", container=False)
|
| 11 |
-
with gr.Column(scale=2):
|
| 12 |
-
gr.Markdown(value="<H2 style='text-align: center;'>NILI Compliance Desktop</h2>")
|
| 13 |
-
with gr.Column(scale=2):
|
| 14 |
-
gr.Markdown("")
|
| 15 |
-
with gr.Tabs() as tabs:
|
| 16 |
-
with gr.Tab(label="Contract Upload", id=0) as upload_tab:
|
| 17 |
-
with gr.Row():
|
| 18 |
-
with gr.Column(variant='panel',scale=1):
|
| 19 |
-
contract_file_cmpt = gr.File(label="Select Contract File",file_count="single",file_types=[".pdf"],height=150)
|
| 20 |
-
with gr.Column(variant='panel',scale=4):
|
| 21 |
-
with gr.Row():
|
| 22 |
-
with gr.Column(variant='panel'):
|
| 23 |
-
contract_text_tbox = gr.Textbox(label="Contract Text",interactive=True,info="Upload .pdf or paste in text. Shift-Enter to add a line")
|
| 24 |
-
with gr.Row():
|
| 25 |
-
with gr.Column(scale=1):
|
| 26 |
-
upload_btn = gr.components.Button(value="Upload Contract", size='sm', variant="primary")
|
| 27 |
-
with gr.Column(scale=2):
|
| 28 |
-
gr.Markdown("")
|
| 29 |
-
with gr.Column(scale=1):
|
| 30 |
-
redline_btn = gr.components.Button(value="Redline Contract", size='sm', variant="primary")
|
| 31 |
-
with gr.Column(scale=2):
|
| 32 |
-
gr.Markdown("")
|
| 33 |
-
with gr.Tab(label="Contract Redline", id=1) as redline_tab:
|
| 34 |
-
with gr.Row(variant='panel'):
|
| 35 |
-
with gr.Column():
|
| 36 |
-
sponsor_tbox = gr.Textbox(label="Sponsor:", interactive=True)
|
| 37 |
-
compensation_num = gr.Number(label="Contract Value",value=0)
|
| 38 |
-
status_ddss = gr.Dropdown(["Pending","Approved","Rejected"],multiselect=False,label="Status", value="Pending")
|
| 39 |
-
with gr.Column():
|
| 40 |
-
name_tbox = gr.Textbox(label="Name:", interactive=True)
|
| 41 |
-
email_tbox = gr.Textbox(label="Email:", interactive=True, type='email',placeholder='xxxxxxx@xxxxxx.xxx')
|
| 42 |
-
with gr.Column():
|
| 43 |
-
start_date_tbox = gr.Textbox(label="Start Date:", interactive=True, placeholder='MM/DD/YYYY')
|
| 44 |
-
end_date_tbox = gr.Textbox(label="End Date:", interactive=True, placeholder='MM/DD/YYYY')
|
| 45 |
-
with gr.Row():
|
| 46 |
-
with gr.Column(variant='panel'):
|
| 47 |
-
gr.components.Markdown(response_label)
|
| 48 |
-
contract_redline_html = gr.HTML(label="Contract Redline")
|
| 49 |
-
compliance_comments_tbox = gr.Textbox(interactive=True,label='Compliance Comments')
|
| 50 |
-
with gr.Row():
|
| 51 |
-
with gr.Column():
|
| 52 |
-
save_btn = gr.Button(value="Save Contract", size='sm', variant="primary")
|
| 53 |
-
with gr.Column():
|
| 54 |
-
gr.Markdown("")
|
| 55 |
-
with gr.Column():
|
| 56 |
-
gr.Markdown("")
|
| 57 |
-
with gr.Column():
|
| 58 |
-
gr.Markdown("")
|
| 59 |
-
with gr.Column():
|
| 60 |
-
gr.Markdown("")
|
| 61 |
-
with gr.Row(visible=False) as download_row:
|
| 62 |
-
with gr.Column(variant='panel'):
|
| 63 |
-
file_name_tbox = gr.Textbox(interactive=False,label='File Name',visible=False)
|
| 64 |
-
pdf_download_file = gr.File()
|
| 65 |
-
download_btn = gr.Button(value="Create Redline PDF", size='sm', variant="primary")
|
| 66 |
-
upload_btn.click(pdf_to_text,inputs=[contract_file_cmpt,contract_text_tbox,file_name_tbox],outputs=[contract_text_tbox,file_name_tbox,contract_redline_html,compliance_comments_tbox,pdf_download_file])
|
| 67 |
-
download_btn.click(download_pdf,inputs=[compliance_comments_tbox,contract_redline_html,file_name_tbox],outputs=pdf_download_file)
|
| 68 |
-
with gr.Column():
|
| 69 |
-
gr.Markdown("")
|
| 70 |
-
with gr.Column():
|
| 71 |
-
gr.Markdown("")
|
| 72 |
-
with gr.Column():
|
| 73 |
-
gr.Markdown("")
|
| 74 |
-
with gr.Column():
|
| 75 |
-
gr.Markdown("")
|
| 76 |
-
with gr.Tab(label="History", id=3) as history_tab:
|
| 77 |
-
with gr.Row():
|
| 78 |
-
with gr.Column(variant='panel'):
|
| 79 |
-
compliance_history_df = gr.Dataframe(get_compliance_history,
|
| 80 |
-
headers=["Sponsor", "Contract Value", "Student Name", "Student Email", "Start Date", "End Date", "Status","Created"],
|
| 81 |
-
datatype=["str", "number", "str", "str", "date", "date", "str","date"],
|
| 82 |
-
label="Contract History",
|
| 83 |
-
interactive=False
|
| 84 |
-
)
|
| 85 |
-
with gr.Tab(label="Settings", id=4) as settings_tab:
|
| 86 |
-
with gr.Row():
|
| 87 |
-
with gr.Column(variant='panel',scale=1):
|
| 88 |
-
policy_name_dd = gr.Dropdown(schools, multiselect=False,label="NIL Policy Selection", value="Wake Forest University")
|
| 89 |
-
policy_name_dd.change(policy_name_change,inputs=policy_name_dd,outputs=None)
|
| 90 |
-
redline_btn.click(change_tab, inputs=contract_text_tbox, outputs=tabs).success(chatbot,inputs=[policy_name_dd,contract_text_tbox],
|
| 91 |
-
outputs=[contract_redline_html,download_row]).then(update_tboxes,inputs=None,
|
| 92 |
-
outputs=[sponsor_tbox,name_tbox,email_tbox,start_date_tbox,end_date_tbox])
|
| 93 |
-
save_btn.click(append_to_at_compliance_history,inputs=[policy_name_dd,contract_redline_html,compliance_comments_tbox,sponsor_tbox,compensation_num,status_ddss,name_tbox,email_tbox,start_date_tbox,end_date_tbox],outputs=compliance_history_df)
|
| 94 |
-
with gr.Column():
|
| 95 |
-
gr.Markdown("")
|
| 96 |
-
with gr.Column():
|
| 97 |
-
gr.Markdown("")
|
| 98 |
-
with gr.Column():
|
| 99 |
-
gr.Markdown("")
|
| 100 |
-
"""
|
| 101 |
-
with gr.Row(visible=True) as login_row:
|
| 102 |
-
with gr.Column():
|
| 103 |
-
with gr.Row():
|
| 104 |
-
with gr.Column(scale=2):
|
| 105 |
-
gr.Markdown("")
|
| 106 |
-
with gr.Column(scale=1):
|
| 107 |
-
with gr.Row():
|
| 108 |
-
gr.Image(label="Logo", value="Nili_v2_Character.png", width=200, height=200,
|
| 109 |
-
show_download_button=False,
|
| 110 |
-
interactive=False, show_label=False, elem_id="logo", container=False)
|
| 111 |
-
with gr.Row():
|
| 112 |
-
gr.Markdown(value="<H2 style='text-align: center;'>NILI Login</h2>")
|
| 113 |
-
with gr.Column(scale=2):
|
| 114 |
-
gr.Markdown("")
|
| 115 |
-
"""
|
| 116 |
-
with gr.Row():
|
| 117 |
-
with gr.Column(scale=2):
|
| 118 |
-
gr.Markdown("")
|
| 119 |
-
with gr.Column(scale=1, variant='panel'):
|
| 120 |
-
username_tbox = gr.Textbox(label="User Name", interactive=True)
|
| 121 |
-
password_tbox = gr.Textbox(label="Password", interactive=True, type='password')
|
| 122 |
-
submit_btn = gr.Button(value='Submit', variant='primary', size='sm')
|
| 123 |
-
submit_btn.click(login_auth, inputs=[username_tbox, password_tbox], outputs=[login_row,app_row])
|
| 124 |
-
with gr.Column(scale=2):
|
| 125 |
-
gr.Markdown("")
|
| 126 |
-
"""
|
| 127 |
with gr.Row():
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def combine(a, b):
|
| 6 |
+
return a + " " + b
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def mirror(x):
|
| 10 |
+
return x
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
|
| 15 |
+
txt = gr.Textbox(label="Input", lines=2)
|
| 16 |
+
txt_2 = gr.Textbox(label="Input 2")
|
| 17 |
+
txt_3 = gr.Textbox(value="", label="Output")
|
| 18 |
+
btn = gr.Button(value="Submit")
|
| 19 |
+
btn.click(combine, inputs=[txt, txt_2], outputs=[txt_3])
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
with gr.Row():
|
| 22 |
+
im = gr.Image()
|
| 23 |
+
im_2 = gr.Image()
|
| 24 |
+
|
| 25 |
+
btn = gr.Button(value="Mirror Image")
|
| 26 |
+
btn.click(mirror, inputs=[im], outputs=[im_2])
|
| 27 |
+
|
| 28 |
+
gr.Markdown("## Text Examples")
|
| 29 |
+
gr.Examples(
|
| 30 |
+
[["hi", "Adam"], ["hello", "Eve"]],
|
| 31 |
+
[txt, txt_2],
|
| 32 |
+
txt_3,
|
| 33 |
+
combine,
|
| 34 |
+
cache_examples=True,
|
| 35 |
+
)
|
| 36 |
+
gr.Markdown("## Image Examples")
|
| 37 |
+
gr.Examples(
|
| 38 |
+
examples=[os.path.join(os.path.dirname(__file__), "lion.jpg")],
|
| 39 |
+
inputs=im,
|
| 40 |
+
outputs=im_2,
|
| 41 |
+
fn=mirror,
|
| 42 |
+
cache_examples=True,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|