Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from tinydb import TinyDB, Query
|
|
| 6 |
import datetime
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
import warnings
|
| 9 |
-
from article_generator import generate_article
|
| 10 |
from tavily_search import create_tavily_search_ui, tavily_search_interface # 追加
|
| 11 |
import time # 追加
|
| 12 |
|
|
@@ -69,22 +69,6 @@ def process_article(new_keyword, other_keywords, action, edited_article_structur
|
|
| 69 |
print(f"予期せぬエラーが発生しました:{str(e)}")
|
| 70 |
return response_text, final_article_content
|
| 71 |
|
| 72 |
-
elif action == "再開":
|
| 73 |
-
response_text = edited_article_structure
|
| 74 |
-
try:
|
| 75 |
-
final_article_content = continue_generate_article()
|
| 76 |
-
|
| 77 |
-
# output3.txt ファイルが作成されるのを待つ
|
| 78 |
-
while not os.path.exists("output3.txt"):
|
| 79 |
-
time.sleep(0.1)
|
| 80 |
-
|
| 81 |
-
with open("output3.txt", "r", encoding="utf-8") as f:
|
| 82 |
-
final_article_content = f.read()
|
| 83 |
-
except Exception as e:
|
| 84 |
-
final_article_content = f"予期せぬエラーが発生しました:{str(e)}"
|
| 85 |
-
print(f"予期せぬエラーが発生しました:{str(e)}")
|
| 86 |
-
return response_text, final_article_content
|
| 87 |
-
|
| 88 |
# Gradioアプリの設定
|
| 89 |
with gr.Blocks(css=".column { float: left; width: 50%; } .clear { clear: both; } .right-align { margin-top: 24px; }") as app:
|
| 90 |
with gr.Row():
|
|
@@ -95,8 +79,6 @@ with gr.Blocks(css=".column { float: left; width: 50%; } .clear { clear: both; }
|
|
| 95 |
create_structure_button = gr.Button("構成作成")
|
| 96 |
editable_output2 = gr.Textbox(label="編集可能な記事構成", lines=10, placeholder="記事構成がここに表示されます")
|
| 97 |
create_article_button = gr.Button("本文作成")
|
| 98 |
-
continue_article_button = gr.Button("続きから再開")
|
| 99 |
-
clear_state_button = gr.Button("状態をクリア")
|
| 100 |
final_article = gr.Textbox(label="最終的な記事本文", lines=10)
|
| 101 |
|
| 102 |
create_structure_button.click(
|
|
@@ -110,18 +92,6 @@ with gr.Blocks(css=".column { float: left; width: 50%; } .clear { clear: both; }
|
|
| 110 |
inputs=[new_keyword, other_keywords, gr.State("本文作成"), editable_output2],
|
| 111 |
outputs=[editable_output2, final_article]
|
| 112 |
)
|
| 113 |
-
|
| 114 |
-
continue_article_button.click(
|
| 115 |
-
fn=process_article,
|
| 116 |
-
inputs=[new_keyword, other_keywords, gr.State("再開"), editable_output2],
|
| 117 |
-
outputs=[editable_output2, final_article]
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
clear_state_button.click(
|
| 121 |
-
fn=clear_state,
|
| 122 |
-
inputs=[],
|
| 123 |
-
outputs=[final_article]
|
| 124 |
-
)
|
| 125 |
|
| 126 |
with gr.Column():
|
| 127 |
gr.Markdown(" ", elem_id="spacer") # 空白を作るための見えないMarkdown
|
|
@@ -136,7 +106,7 @@ with gr.Blocks(css=".column { float: left; width: 50%; } .clear { clear: both; }
|
|
| 136 |
if format == "Markdown":
|
| 137 |
return gr.update(visible=True), gr.update(visible=False)
|
| 138 |
else:
|
| 139 |
-
return gr.update(visible
|
| 140 |
|
| 141 |
search_button.click(tavily_search_interface, inputs=[selected_text, domain_filter], outputs=[search_results_md, search_results_html])
|
| 142 |
display_format.change(switch_display_format, inputs=display_format, outputs=[search_results_md, search_results_html])
|
|
|
|
| 6 |
import datetime
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
import warnings
|
| 9 |
+
from article_generator import generate_article # clear_state と continue_generate_article を削除
|
| 10 |
from tavily_search import create_tavily_search_ui, tavily_search_interface # 追加
|
| 11 |
import time # 追加
|
| 12 |
|
|
|
|
| 69 |
print(f"予期せぬエラーが発生しました:{str(e)}")
|
| 70 |
return response_text, final_article_content
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# Gradioアプリの設定
|
| 73 |
with gr.Blocks(css=".column { float: left; width: 50%; } .clear { clear: both; } .right-align { margin-top: 24px; }") as app:
|
| 74 |
with gr.Row():
|
|
|
|
| 79 |
create_structure_button = gr.Button("構成作成")
|
| 80 |
editable_output2 = gr.Textbox(label="編集可能な記事構成", lines=10, placeholder="記事構成がここに表示されます")
|
| 81 |
create_article_button = gr.Button("本文作成")
|
|
|
|
|
|
|
| 82 |
final_article = gr.Textbox(label="最終的な記事本文", lines=10)
|
| 83 |
|
| 84 |
create_structure_button.click(
|
|
|
|
| 92 |
inputs=[new_keyword, other_keywords, gr.State("本文作成"), editable_output2],
|
| 93 |
outputs=[editable_output2, final_article]
|
| 94 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
with gr.Column():
|
| 97 |
gr.Markdown(" ", elem_id="spacer") # 空白を作るための見えないMarkdown
|
|
|
|
| 106 |
if format == "Markdown":
|
| 107 |
return gr.update(visible=True), gr.update(visible=False)
|
| 108 |
else:
|
| 109 |
+
return gr.update(visible(False)), gr.update(visible=True)
|
| 110 |
|
| 111 |
search_button.click(tavily_search_interface, inputs=[selected_text, domain_filter], outputs=[search_results_md, search_results_html])
|
| 112 |
display_format.change(switch_display_format, inputs=display_format, outputs=[search_results_md, search_results_html])
|