Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,7 @@ def get_top_urls_and_keyword(keyword):
|
|
| 27 |
).execute()
|
| 28 |
|
| 29 |
urls = [item['link'] for item in response["items"][:3]]
|
|
|
|
| 30 |
return urls, keyword
|
| 31 |
|
| 32 |
def get_valid_url(urls):
|
|
@@ -63,10 +64,8 @@ db.remove(Query().timestamp.test(lambda x: datetime.datetime.fromisoformat(x) <=
|
|
| 63 |
|
| 64 |
st.title("記事生成ウェブアプリ")
|
| 65 |
st.write("このアプリは、与えられたキーワードを使用して記事を生成します。")
|
| 66 |
-
|
| 67 |
new_keyword = st.text_input("キーワード:")
|
| 68 |
keyword_id = re.sub(r"\W+", "", new_keyword) if new_keyword else None
|
| 69 |
-
|
| 70 |
last_keyword = db.search(Query().keyword_id.exists())
|
| 71 |
|
| 72 |
if new_keyword and (not last_keyword or last_keyword[0]['keyword_id'] != keyword_id):
|
|
@@ -102,23 +101,22 @@ if keyword_id:
|
|
| 102 |
editable_output2 = ""
|
| 103 |
|
| 104 |
if st.button("記事構成作成", key=f"run_button_{keyword_id}"):
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
editable_output2 = f.read()
|
| 122 |
soup = BeautifulSoup(editable_output2, "html.parser")
|
| 123 |
h_tags = soup.find_all(re.compile("^h[1-3]$"))
|
| 124 |
output2.text(editable_output2)
|
|
@@ -133,25 +131,16 @@ if keyword_id:
|
|
| 133 |
{"name": "output2.txt", "content": editable_output2, "tags": str(h_tags),
|
| 134 |
"timestamp": current_time.isoformat(), "keyword_id": keyword_id}
|
| 135 |
)
|
| 136 |
-
|
| 137 |
-
except subprocess.CalledProcessError:
|
| 138 |
-
st.error("記事の構成作成中にエラーが発生しました。もう一度お試しください。")
|
| 139 |
-
except Exception as e:
|
| 140 |
-
st.error(f"予期せぬエラーが発生しました:{str(e)}")
|
| 141 |
|
| 142 |
editable_output2 = st.text_area("output2.txtを編集してください:", value=editable_output2)
|
| 143 |
|
| 144 |
if st.button("記事作成"):
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
output3.text(content)
|
| 151 |
-
except subprocess.CalledProcessError:
|
| 152 |
-
st.error("記事作成中にエラーが発生しました。もう一度お試しください。")
|
| 153 |
-
except Exception as e:
|
| 154 |
-
st.error(f"予期せぬエラーが発生しました:{str(e)}")
|
| 155 |
|
| 156 |
if st.button("保存"):
|
| 157 |
h2_limit = 5
|
|
|
|
| 27 |
).execute()
|
| 28 |
|
| 29 |
urls = [item['link'] for item in response["items"][:3]]
|
| 30 |
+
|
| 31 |
return urls, keyword
|
| 32 |
|
| 33 |
def get_valid_url(urls):
|
|
|
|
| 64 |
|
| 65 |
st.title("記事生成ウェブアプリ")
|
| 66 |
st.write("このアプリは、与えられたキーワードを使用して記事を生成します。")
|
|
|
|
| 67 |
new_keyword = st.text_input("キーワード:")
|
| 68 |
keyword_id = re.sub(r"\W+", "", new_keyword) if new_keyword else None
|
|
|
|
| 69 |
last_keyword = db.search(Query().keyword_id.exists())
|
| 70 |
|
| 71 |
if new_keyword and (not last_keyword or last_keyword[0]['keyword_id'] != keyword_id):
|
|
|
|
| 101 |
editable_output2 = ""
|
| 102 |
|
| 103 |
if st.button("記事構成作成", key=f"run_button_{keyword_id}"):
|
| 104 |
+
with st.spinner("タイトル・見出し作成中..."):
|
| 105 |
+
urls, keyword = get_top_urls_and_keyword(new_keyword)
|
| 106 |
+
url1, url2, url3 = urls
|
| 107 |
+
parsed_urls = [urlparse(url) for url in urls]
|
| 108 |
+
if len(urls) != len(set(urls)):
|
| 109 |
+
st.error("異なるURLを入力してください。")
|
| 110 |
+
st.stop()
|
| 111 |
+
elif len(set([url.netloc for url in parsed_urls])) != len(urls):
|
| 112 |
+
st.error("異なるサイトのURLを入力してください。")
|
| 113 |
+
st.stop()
|
| 114 |
+
subprocess.run(["python3", "first.py", url1, url2, url3])
|
| 115 |
+
|
| 116 |
+
with st.spinner("関連コンテンツ抽出中..."): # 新しいスピナーを追加
|
| 117 |
+
subprocess.run(["python3", "second.py", keyword])
|
| 118 |
+
with open("output2.txt", "r", encoding="utf-8") as f:
|
| 119 |
+
editable_output2 = f.read()
|
|
|
|
| 120 |
soup = BeautifulSoup(editable_output2, "html.parser")
|
| 121 |
h_tags = soup.find_all(re.compile("^h[1-3]$"))
|
| 122 |
output2.text(editable_output2)
|
|
|
|
| 131 |
{"name": "output2.txt", "content": editable_output2, "tags": str(h_tags),
|
| 132 |
"timestamp": current_time.isoformat(), "keyword_id": keyword_id}
|
| 133 |
)
|
| 134 |
+
st.success("処理が完了しました。")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
editable_output2 = st.text_area("output2.txtを編集してください:", value=editable_output2)
|
| 137 |
|
| 138 |
if st.button("記事作成"):
|
| 139 |
+
with st.spinner("記事作成中..."):
|
| 140 |
+
subprocess.run(["python3", "run_third.py", editable_output2, keyword_id])
|
| 141 |
+
with open("output3.txt", "r", encoding="utf-8") as f:
|
| 142 |
+
content = f.read()
|
| 143 |
+
output3.text(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
if st.button("保存"):
|
| 146 |
h2_limit = 5
|