Spaces:
Runtime error
Runtime error
fixed shared history + add clear history button
Browse files
app.py
CHANGED
@@ -377,11 +377,13 @@ def generate_article(
|
|
377 |
return clean_text(article)
|
378 |
|
379 |
|
380 |
-
history
|
|
|
381 |
|
382 |
|
383 |
-
def
|
384 |
-
|
|
|
385 |
|
386 |
|
387 |
def humanize(
|
@@ -391,6 +393,7 @@ def humanize(
|
|
391 |
repetition_penalty: float = 1,
|
392 |
top_k: int = 50,
|
393 |
length_penalty: float = 1,
|
|
|
394 |
) -> str:
|
395 |
print("Humanizing text...")
|
396 |
body, references = split_text_from_refs(text)
|
@@ -407,7 +410,7 @@ def humanize(
|
|
407 |
|
408 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
409 |
history.append((f"Humanized Text | {timestamp}\nInput: {model}", corrected_text))
|
410 |
-
return corrected_text
|
411 |
|
412 |
|
413 |
def update_visibility_api(model: str):
|
@@ -443,6 +446,7 @@ def generate_and_format(
|
|
443 |
include_sites,
|
444 |
exclude_sites,
|
445 |
pdf_file_input,
|
|
|
446 |
ai_model="OpenAI GPT 4o",
|
447 |
api_key=None,
|
448 |
generated_article: str = None,
|
@@ -500,7 +504,7 @@ def generate_and_format(
|
|
500 |
reference_formatted = format_references(article)
|
501 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
502 |
history.append((f"Generated Text | {timestamp}\nInput: {topic}", reference_formatted))
|
503 |
-
return reference_formatted
|
504 |
|
505 |
|
506 |
def create_interface():
|
@@ -512,6 +516,7 @@ def create_interface():
|
|
512 |
.input-highlight-pink block_label {background-color: #008080}
|
513 |
""",
|
514 |
) as demo:
|
|
|
515 |
today = date.today()
|
516 |
# dd/mm/YY
|
517 |
d1 = today.strftime("%d/%B/%Y")
|
@@ -766,6 +771,8 @@ def create_interface():
|
|
766 |
|
767 |
with gr.Tab("History"):
|
768 |
history_chat = gr.Chatbot(label="Generation History", height=1000)
|
|
|
|
|
769 |
"""
|
770 |
# NOTE: REMOVED REFRESH BUTTON
|
771 |
refresh_button = gr.Button("Refresh History")
|
@@ -826,8 +833,9 @@ def create_interface():
|
|
826 |
include_sites,
|
827 |
exclude_sites,
|
828 |
pdf_file_input,
|
|
|
829 |
],
|
830 |
-
outputs=[output_article],
|
831 |
)
|
832 |
|
833 |
regenerate_btn.click(
|
@@ -858,12 +866,13 @@ def create_interface():
|
|
858 |
day_to,
|
859 |
domains_to_include,
|
860 |
pdf_file_input,
|
|
|
861 |
output_article,
|
862 |
include_sites,
|
863 |
exclude_sites,
|
864 |
ai_comments,
|
865 |
],
|
866 |
-
outputs=[output_article],
|
867 |
)
|
868 |
|
869 |
ai_check_btn.click(
|
@@ -881,13 +890,14 @@ def create_interface():
|
|
881 |
repetition_penalty_slider,
|
882 |
top_k_slider,
|
883 |
length_penalty_slider,
|
|
|
884 |
],
|
885 |
-
outputs=[output_article],
|
886 |
)
|
887 |
|
888 |
-
generate_btn.click(get_history, outputs=history_chat)
|
889 |
-
regenerate_btn.click(get_history, outputs=history_chat)
|
890 |
-
humanize_btn.click(get_history, outputs=history_chat)
|
891 |
|
892 |
return demo
|
893 |
|
|
|
377 |
return clean_text(article)
|
378 |
|
379 |
|
380 |
+
def get_history(history):
|
381 |
+
return history
|
382 |
|
383 |
|
384 |
+
def clear_history():
|
385 |
+
# Return empty list for history state and display
|
386 |
+
return [], []
|
387 |
|
388 |
|
389 |
def humanize(
|
|
|
393 |
repetition_penalty: float = 1,
|
394 |
top_k: int = 50,
|
395 |
length_penalty: float = 1,
|
396 |
+
history=None,
|
397 |
) -> str:
|
398 |
print("Humanizing text...")
|
399 |
body, references = split_text_from_refs(text)
|
|
|
410 |
|
411 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
412 |
history.append((f"Humanized Text | {timestamp}\nInput: {model}", corrected_text))
|
413 |
+
return corrected_text, history
|
414 |
|
415 |
|
416 |
def update_visibility_api(model: str):
|
|
|
446 |
include_sites,
|
447 |
exclude_sites,
|
448 |
pdf_file_input,
|
449 |
+
history=None,
|
450 |
ai_model="OpenAI GPT 4o",
|
451 |
api_key=None,
|
452 |
generated_article: str = None,
|
|
|
504 |
reference_formatted = format_references(article)
|
505 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
506 |
history.append((f"Generated Text | {timestamp}\nInput: {topic}", reference_formatted))
|
507 |
+
return reference_formatted, history
|
508 |
|
509 |
|
510 |
def create_interface():
|
|
|
516 |
.input-highlight-pink block_label {background-color: #008080}
|
517 |
""",
|
518 |
) as demo:
|
519 |
+
history = gr.State([])
|
520 |
today = date.today()
|
521 |
# dd/mm/YY
|
522 |
d1 = today.strftime("%d/%B/%Y")
|
|
|
771 |
|
772 |
with gr.Tab("History"):
|
773 |
history_chat = gr.Chatbot(label="Generation History", height=1000)
|
774 |
+
clear_history_btn = gr.Button("Clear History")
|
775 |
+
clear_history_btn.click(clear_history, outputs=[history, history_chat])
|
776 |
"""
|
777 |
# NOTE: REMOVED REFRESH BUTTON
|
778 |
refresh_button = gr.Button("Refresh History")
|
|
|
833 |
include_sites,
|
834 |
exclude_sites,
|
835 |
pdf_file_input,
|
836 |
+
history,
|
837 |
],
|
838 |
+
outputs=[output_article, history],
|
839 |
)
|
840 |
|
841 |
regenerate_btn.click(
|
|
|
866 |
day_to,
|
867 |
domains_to_include,
|
868 |
pdf_file_input,
|
869 |
+
history,
|
870 |
output_article,
|
871 |
include_sites,
|
872 |
exclude_sites,
|
873 |
ai_comments,
|
874 |
],
|
875 |
+
outputs=[output_article, history],
|
876 |
)
|
877 |
|
878 |
ai_check_btn.click(
|
|
|
890 |
repetition_penalty_slider,
|
891 |
top_k_slider,
|
892 |
length_penalty_slider,
|
893 |
+
history,
|
894 |
],
|
895 |
+
outputs=[output_article, history],
|
896 |
)
|
897 |
|
898 |
+
generate_btn.click(get_history, inputs=[history], outputs=[history_chat])
|
899 |
+
regenerate_btn.click(get_history, inputs=[history], outputs=[history_chat])
|
900 |
+
humanize_btn.click(get_history, inputs=[history], outputs=[history_chat])
|
901 |
|
902 |
return demo
|
903 |
|