Upload app.py
Browse filesdisable APIs from frontend
app.py
CHANGED
@@ -27,6 +27,8 @@ except ImportError:
|
|
27 |
)
|
28 |
from constants import JS, CATEGORIES
|
29 |
|
|
|
|
|
30 |
|
31 |
class LoggedComponents(TypedDict):
|
32 |
context: List[gr.components.Component]
|
@@ -93,7 +95,7 @@ def generate_pdf(*sections: str) -> str:
|
|
93 |
pdf.multi_cell(w=0, h=line_height, text=section)
|
94 |
pdf.ln(line_height) # Single spacing
|
95 |
|
96 |
-
pdf_output = "/tmp
|
97 |
pdf.output(pdf_output)
|
98 |
return pdf_output
|
99 |
|
@@ -128,13 +130,15 @@ def generate_docx(*sections: str) -> str:
|
|
128 |
for section in sections:
|
129 |
doc.add_paragraph(section)
|
130 |
|
131 |
-
docx_output = "/tmp
|
132 |
doc.save(docx_output)
|
133 |
return docx_output
|
134 |
|
135 |
|
136 |
def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
137 |
-
|
|
|
|
|
138 |
gr.Markdown(
|
139 |
"""
|
140 |
<h1>Demo: LOI writer</h1>
|
@@ -246,7 +250,9 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
246 |
button_help.click(
|
247 |
help_mission_statement,
|
248 |
inputs=[org_name_text, textbox_info],
|
249 |
-
outputs=[org_mission_statement_text]
|
|
|
|
|
250 |
)
|
251 |
|
252 |
foundation_mission_statement_text = gr.Textbox(
|
@@ -400,7 +406,9 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
400 |
generate_pdf,
|
401 |
inputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
402 |
outputs=gr.File(label="Download as PDF"),
|
403 |
-
scroll_to_output=True
|
|
|
|
|
404 |
)
|
405 |
|
406 |
# pylint: disable=no-member
|
@@ -408,7 +416,9 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
408 |
generate_docx,
|
409 |
inputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
410 |
outputs=gr.File(label="Download as docx"),
|
411 |
-
scroll_to_output=True
|
|
|
|
|
412 |
)
|
413 |
|
414 |
# pylint: disable=no-member
|
@@ -429,6 +439,7 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
429 |
funder_candid_id
|
430 |
],
|
431 |
scroll_to_output=True,
|
|
|
432 |
api_name=False,
|
433 |
queue=True,
|
434 |
)
|
@@ -442,11 +453,12 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
442 |
projects_text
|
443 |
],
|
444 |
outputs=[amount_estimate_text],
|
|
|
445 |
api_name=False,
|
446 |
queue=True
|
447 |
)
|
448 |
|
449 |
-
data_source_button.click(fn=update_links, inputs=category_dropdown, outputs=link_markdown)
|
450 |
|
451 |
write_btn.click(
|
452 |
fn=draft_letter,
|
@@ -478,6 +490,7 @@ def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
|
478 |
],
|
479 |
outputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
480 |
scroll_to_output=True,
|
|
|
481 |
api_name=False,
|
482 |
queue=True,
|
483 |
)
|
@@ -605,6 +618,8 @@ def build_feedback(components: LoggedComponents) -> gr.Blocks:
|
|
605 |
fn=handle_feedback,
|
606 |
inputs=[comp for k, cl in components.items() for comp in (cl if isinstance(cl, list) else [cl])],
|
607 |
outputs=None,
|
|
|
|
|
608 |
preprocess=False,
|
609 |
)
|
610 |
return demo
|
@@ -630,5 +645,5 @@ if __name__ == '__main__':
|
|
630 |
(os.getenv("APP_USERNAME"), os.getenv("APP_PASSWORD")),
|
631 |
(os.getenv("APP_PUBLIC_USERNAME"), os.getenv("APP_PUBLIC_PASSWORD")),
|
632 |
],
|
633 |
-
auth_message="Login to Candid's letter of intent demo"
|
634 |
)
|
|
|
27 |
)
|
28 |
from constants import JS, CATEGORIES
|
29 |
|
30 |
+
os.environ["GRADIO_TEMP_DIR"] = "/tmp"
|
31 |
+
|
32 |
|
33 |
class LoggedComponents(TypedDict):
|
34 |
context: List[gr.components.Component]
|
|
|
95 |
pdf.multi_cell(w=0, h=line_height, text=section)
|
96 |
pdf.ln(line_height) # Single spacing
|
97 |
|
98 |
+
pdf_output = os.path.join(os.getenv("GRADIO_TEMP_DIR", "/tmp"), "LOI_by_Candid_AI.pdf")
|
99 |
pdf.output(pdf_output)
|
100 |
return pdf_output
|
101 |
|
|
|
130 |
for section in sections:
|
131 |
doc.add_paragraph(section)
|
132 |
|
133 |
+
docx_output = os.path.join(os.getenv("GRADIO_TEMP_DIR", "/tmp"), "LOI_by_Candid_AI.docx")
|
134 |
doc.save(docx_output)
|
135 |
return docx_output
|
136 |
|
137 |
|
138 |
def build_drafter() -> Tuple[LoggedComponents, gr.Blocks]:
|
139 |
+
# delete_cache is tuple (frequency, age) where age is in seconds
|
140 |
+
# frequency is provided as an integer num_seconds as well where the deletion occurrence is 1 / num_seconds
|
141 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="LOI writer", delete_cache=(30, 30)) as demo:
|
142 |
gr.Markdown(
|
143 |
"""
|
144 |
<h1>Demo: LOI writer</h1>
|
|
|
250 |
button_help.click(
|
251 |
help_mission_statement,
|
252 |
inputs=[org_name_text, textbox_info],
|
253 |
+
outputs=[org_mission_statement_text],
|
254 |
+
show_api=False,
|
255 |
+
api_name=False,
|
256 |
)
|
257 |
|
258 |
foundation_mission_statement_text = gr.Textbox(
|
|
|
406 |
generate_pdf,
|
407 |
inputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
408 |
outputs=gr.File(label="Download as PDF"),
|
409 |
+
scroll_to_output=True,
|
410 |
+
show_api=False,
|
411 |
+
api_name=False,
|
412 |
)
|
413 |
|
414 |
# pylint: disable=no-member
|
|
|
416 |
generate_docx,
|
417 |
inputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
418 |
outputs=gr.File(label="Download as docx"),
|
419 |
+
scroll_to_output=True,
|
420 |
+
show_api=False,
|
421 |
+
api_name=False,
|
422 |
)
|
423 |
|
424 |
# pylint: disable=no-member
|
|
|
439 |
funder_candid_id
|
440 |
],
|
441 |
scroll_to_output=True,
|
442 |
+
show_api=False,
|
443 |
api_name=False,
|
444 |
queue=True,
|
445 |
)
|
|
|
453 |
projects_text
|
454 |
],
|
455 |
outputs=[amount_estimate_text],
|
456 |
+
show_api=False,
|
457 |
api_name=False,
|
458 |
queue=True
|
459 |
)
|
460 |
|
461 |
+
data_source_button.click(fn=update_links, inputs=category_dropdown, outputs=link_markdown, show_api=False)
|
462 |
|
463 |
write_btn.click(
|
464 |
fn=draft_letter,
|
|
|
490 |
],
|
491 |
outputs=[opening, org_desc, need, project_desc, fund_request, conclusion],
|
492 |
scroll_to_output=True,
|
493 |
+
show_api=False,
|
494 |
api_name=False,
|
495 |
queue=True,
|
496 |
)
|
|
|
618 |
fn=handle_feedback,
|
619 |
inputs=[comp for k, cl in components.items() for comp in (cl if isinstance(cl, list) else [cl])],
|
620 |
outputs=None,
|
621 |
+
show_api=False,
|
622 |
+
api_name=False,
|
623 |
preprocess=False,
|
624 |
)
|
625 |
return demo
|
|
|
645 |
(os.getenv("APP_USERNAME"), os.getenv("APP_PASSWORD")),
|
646 |
(os.getenv("APP_PUBLIC_USERNAME"), os.getenv("APP_PUBLIC_PASSWORD")),
|
647 |
],
|
648 |
+
auth_message="Login to Candid's letter of intent demo",
|
649 |
)
|