Update app.py
Browse files
app.py
CHANGED
@@ -94,21 +94,20 @@ def find_paper_in_sheet(paper_id):
|
|
94 |
return None
|
95 |
|
96 |
def gradio_interface(selected_date_str, today_pressed):
|
97 |
-
#
|
|
|
|
|
98 |
if today_pressed:
|
99 |
-
|
100 |
-
paper_links = fetch_paper_links("https://huggingface.co/papers")
|
101 |
else:
|
102 |
try:
|
103 |
-
#
|
104 |
datetime.strptime(selected_date_str, "%Y-%m-%d")
|
105 |
date = selected_date_str
|
106 |
except ValueError:
|
107 |
# 日付形式が無効な場合、エラーメッセージを返します。
|
108 |
return "入力された日付が無効です。YYYY-MM-DD形式で入力してください。"
|
109 |
-
|
110 |
-
url = f"https://huggingface.co/papers?date={date}"
|
111 |
-
paper_links = fetch_paper_links(url)
|
112 |
|
113 |
paper_ids = set(link.split('/')[-1] for link in paper_links)
|
114 |
|
@@ -118,7 +117,7 @@ def gradio_interface(selected_date_str, today_pressed):
|
|
118 |
for paper_id in paper_ids:
|
119 |
summary_info = ""
|
120 |
summary = find_paper_in_sheet(paper_id)
|
121 |
-
if summary
|
122 |
summary, tokens_used = summarize_paper_and_save_to_sheet(paper_id)
|
123 |
total_tokens_used += tokens_used
|
124 |
|
@@ -130,6 +129,7 @@ def gradio_interface(selected_date_str, today_pressed):
|
|
130 |
summaries_markdown = "\n---\n".join(summaries) # 要約を水平線で区切る
|
131 |
return summaries_markdown
|
132 |
|
|
|
133 |
inputs = [
|
134 |
gr.Text(label="日付をYYYY-MM-DD形式で入力", placeholder="例: 2024-03-28"),
|
135 |
gr.Button("Today")
|
@@ -139,9 +139,9 @@ iface = gr.Interface(
|
|
139 |
fn=gradio_interface,
|
140 |
inputs=inputs,
|
141 |
outputs=gr.Markdown(),
|
142 |
-
title="
|
143 |
description="[Daily Papers](https://huggingface.co/papers)に掲載された論文を日本語で要約します。"
|
144 |
)
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
-
iface.launch()
|
|
|
94 |
return None
|
95 |
|
96 |
def gradio_interface(selected_date_str, today_pressed):
|
97 |
+
# 現在の日付を YYYY-MM-DD 形式で取得
|
98 |
+
current_date_str = datetime.now().strftime("%Y-%m-%d")
|
99 |
+
|
100 |
if today_pressed:
|
101 |
+
paper_links = fetch_paper_links(f"https://huggingface.co/papers")
|
|
|
102 |
else:
|
103 |
try:
|
104 |
+
# 日付文字列を検証し、正しい場合はその値を使用
|
105 |
datetime.strptime(selected_date_str, "%Y-%m-%d")
|
106 |
date = selected_date_str
|
107 |
except ValueError:
|
108 |
# 日付形式が無効な場合、エラーメッセージを返します。
|
109 |
return "入力された日付が無効です。YYYY-MM-DD形式で入力してください。"
|
110 |
+
paper_links = fetch_paper_links(f"https://huggingface.co/papers?date={date}")
|
|
|
|
|
111 |
|
112 |
paper_ids = set(link.split('/')[-1] for link in paper_links)
|
113 |
|
|
|
117 |
for paper_id in paper_ids:
|
118 |
summary_info = ""
|
119 |
summary = find_paper_in_sheet(paper_id)
|
120 |
+
if summary is None:
|
121 |
summary, tokens_used = summarize_paper_and_save_to_sheet(paper_id)
|
122 |
total_tokens_used += tokens_used
|
123 |
|
|
|
129 |
summaries_markdown = "\n---\n".join(summaries) # 要約を水平線で区切る
|
130 |
return summaries_markdown
|
131 |
|
132 |
+
# Gradio インターフェースの設定
|
133 |
inputs = [
|
134 |
gr.Text(label="日付をYYYY-MM-DD形式で入力", placeholder="例: 2024-03-28"),
|
135 |
gr.Button("Today")
|
|
|
139 |
fn=gradio_interface,
|
140 |
inputs=inputs,
|
141 |
outputs=gr.Markdown(),
|
142 |
+
title="Daily Papers 日本語要約ツール",
|
143 |
description="[Daily Papers](https://huggingface.co/papers)に掲載された論文を日本語で要約します。"
|
144 |
)
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
+
iface.launch()
|