Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,10 +16,9 @@ class PaperManager:
|
|
| 16 |
response = requests.get(f"{API_URL}?limit=50")
|
| 17 |
response.raise_for_status()
|
| 18 |
data = response.json()
|
| 19 |
-
# Sort papers by upvotes (descending order)
|
| 20 |
self.papers = sorted(data, key=lambda x: x.get('paper', {}).get('upvotes', 0), reverse=True)
|
| 21 |
self.total_pages = (len(self.papers) + self.papers_per_page - 1) // self.papers_per_page
|
| 22 |
-
self.current_page = 1
|
| 23 |
return True
|
| 24 |
except requests.RequestException as e:
|
| 25 |
print(f"Error fetching papers: {e}")
|
|
@@ -38,10 +37,10 @@ class PaperManager:
|
|
| 38 |
<div class="paper-item">
|
| 39 |
<h3><a href="{url}" target="_blank">{title}</a></h3>
|
| 40 |
<p class="paper-meta">
|
| 41 |
-
<span class="upvotes">{upvotes}
|
| 42 |
-
<span class="authors">
|
| 43 |
-
<span class="time-ago">{time_ago}
|
| 44 |
-
<span class="comments">{comments}
|
| 45 |
</p>
|
| 46 |
</div>
|
| 47 |
"""
|
|
@@ -76,50 +75,49 @@ class PaperManager:
|
|
| 76 |
|
| 77 |
css = """
|
| 78 |
body {
|
| 79 |
-
font-family: 'Roboto', sans-serif;
|
| 80 |
background-color: #f0f2f5;
|
| 81 |
margin: 0;
|
| 82 |
padding: 0;
|
| 83 |
}
|
| 84 |
.container {
|
| 85 |
-
max-width:
|
| 86 |
-
margin:
|
| 87 |
background-color: white;
|
| 88 |
-
|
| 89 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 90 |
-
padding: 2rem;
|
| 91 |
}
|
| 92 |
.title {
|
| 93 |
text-align: center;
|
| 94 |
color: #1a202c;
|
| 95 |
-
font-size:
|
| 96 |
-
margin-bottom:
|
| 97 |
}
|
| 98 |
.search-row {
|
| 99 |
display: flex;
|
| 100 |
-
gap:
|
| 101 |
-
margin-bottom:
|
| 102 |
align-items: flex-end;
|
| 103 |
}
|
| 104 |
.search-row > div:first-child {
|
| 105 |
flex-grow: 1;
|
| 106 |
}
|
| 107 |
.paper-list {
|
| 108 |
-
max-height:
|
| 109 |
overflow-y: auto;
|
| 110 |
border: 1px solid #e2e8f0;
|
| 111 |
border-radius: 8px;
|
| 112 |
-
padding:
|
| 113 |
}
|
| 114 |
.paper-item {
|
| 115 |
border-bottom: 1px solid #e2e8f0;
|
| 116 |
-
padding:
|
| 117 |
}
|
| 118 |
.paper-item:last-child {
|
| 119 |
border-bottom: none;
|
| 120 |
}
|
| 121 |
.paper-item h3 {
|
| 122 |
-
margin: 0 0 0.
|
|
|
|
| 123 |
}
|
| 124 |
.paper-item a {
|
| 125 |
color: #2b6cb0;
|
|
@@ -130,20 +128,23 @@ body {
|
|
| 130 |
text-decoration: underline;
|
| 131 |
}
|
| 132 |
.paper-meta {
|
| 133 |
-
font-size: 0.
|
| 134 |
color: #4a5568;
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
.footer {
|
| 137 |
display: flex;
|
| 138 |
justify-content: space-between;
|
| 139 |
align-items: center;
|
| 140 |
-
margin-top:
|
| 141 |
}
|
| 142 |
button, .button {
|
| 143 |
background-color: #4299e1;
|
| 144 |
color: white;
|
| 145 |
border: none;
|
| 146 |
-
padding: 0.5rem
|
| 147 |
border-radius: 4px;
|
| 148 |
cursor: pointer;
|
| 149 |
transition: background-color 0.3s;
|
|
@@ -167,6 +168,28 @@ button:hover, .button:hover {
|
|
| 167 |
border-top-left-radius: 0;
|
| 168 |
border-bottom-left-radius: 0;
|
| 169 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
"""
|
| 171 |
|
| 172 |
paper_manager = PaperManager()
|
|
@@ -187,16 +210,16 @@ demo = gr.Blocks(css=css)
|
|
| 187 |
|
| 188 |
with demo:
|
| 189 |
with gr.Column(elem_classes=["container"]):
|
| 190 |
-
gr.Markdown("# Daily Papers
|
| 191 |
with gr.Row(elem_classes=["search-row"]):
|
| 192 |
-
search_input = gr.Textbox(label="
|
| 193 |
-
refresh_button = gr.Button("
|
| 194 |
paper_list = gr.HTML(elem_classes=["paper-list"])
|
| 195 |
|
| 196 |
with gr.Row(elem_classes=["footer"]):
|
| 197 |
-
prev_button = gr.Button("
|
| 198 |
page_info = gr.Markdown()
|
| 199 |
-
next_button = gr.Button("Next
|
| 200 |
|
| 201 |
demo.load(initialize_app, outputs=[paper_list, page_info])
|
| 202 |
search_input.change(paper_manager.search_papers, inputs=[search_input], outputs=[paper_list])
|
|
|
|
| 16 |
response = requests.get(f"{API_URL}?limit=50")
|
| 17 |
response.raise_for_status()
|
| 18 |
data = response.json()
|
|
|
|
| 19 |
self.papers = sorted(data, key=lambda x: x.get('paper', {}).get('upvotes', 0), reverse=True)
|
| 20 |
self.total_pages = (len(self.papers) + self.papers_per_page - 1) // self.papers_per_page
|
| 21 |
+
self.current_page = 1
|
| 22 |
return True
|
| 23 |
except requests.RequestException as e:
|
| 24 |
print(f"Error fetching papers: {e}")
|
|
|
|
| 37 |
<div class="paper-item">
|
| 38 |
<h3><a href="{url}" target="_blank">{title}</a></h3>
|
| 39 |
<p class="paper-meta">
|
| 40 |
+
<span class="upvotes">{upvotes} ▲</span>
|
| 41 |
+
<span class="authors">{authors}</span>
|
| 42 |
+
<span class="time-ago">{time_ago}d</span>
|
| 43 |
+
<span class="comments">{comments}💬</span>
|
| 44 |
</p>
|
| 45 |
</div>
|
| 46 |
"""
|
|
|
|
| 75 |
|
| 76 |
css = """
|
| 77 |
body {
|
| 78 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
|
| 79 |
background-color: #f0f2f5;
|
| 80 |
margin: 0;
|
| 81 |
padding: 0;
|
| 82 |
}
|
| 83 |
.container {
|
| 84 |
+
max-width: 100%;
|
| 85 |
+
margin: 0 auto;
|
| 86 |
background-color: white;
|
| 87 |
+
padding: 1rem;
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
.title {
|
| 90 |
text-align: center;
|
| 91 |
color: #1a202c;
|
| 92 |
+
font-size: 1.5rem;
|
| 93 |
+
margin-bottom: 1rem;
|
| 94 |
}
|
| 95 |
.search-row {
|
| 96 |
display: flex;
|
| 97 |
+
gap: 0.5rem;
|
| 98 |
+
margin-bottom: 1rem;
|
| 99 |
align-items: flex-end;
|
| 100 |
}
|
| 101 |
.search-row > div:first-child {
|
| 102 |
flex-grow: 1;
|
| 103 |
}
|
| 104 |
.paper-list {
|
| 105 |
+
max-height: 70vh;
|
| 106 |
overflow-y: auto;
|
| 107 |
border: 1px solid #e2e8f0;
|
| 108 |
border-radius: 8px;
|
| 109 |
+
padding: 0.5rem;
|
| 110 |
}
|
| 111 |
.paper-item {
|
| 112 |
border-bottom: 1px solid #e2e8f0;
|
| 113 |
+
padding: 0.5rem 0;
|
| 114 |
}
|
| 115 |
.paper-item:last-child {
|
| 116 |
border-bottom: none;
|
| 117 |
}
|
| 118 |
.paper-item h3 {
|
| 119 |
+
margin: 0 0 0.25rem 0;
|
| 120 |
+
font-size: 1rem;
|
| 121 |
}
|
| 122 |
.paper-item a {
|
| 123 |
color: #2b6cb0;
|
|
|
|
| 128 |
text-decoration: underline;
|
| 129 |
}
|
| 130 |
.paper-meta {
|
| 131 |
+
font-size: 0.75rem;
|
| 132 |
color: #4a5568;
|
| 133 |
+
display: flex;
|
| 134 |
+
flex-wrap: wrap;
|
| 135 |
+
gap: 0.5rem;
|
| 136 |
}
|
| 137 |
.footer {
|
| 138 |
display: flex;
|
| 139 |
justify-content: space-between;
|
| 140 |
align-items: center;
|
| 141 |
+
margin-top: 0.5rem;
|
| 142 |
}
|
| 143 |
button, .button {
|
| 144 |
background-color: #4299e1;
|
| 145 |
color: white;
|
| 146 |
border: none;
|
| 147 |
+
padding: 0.25rem 0.5rem;
|
| 148 |
border-radius: 4px;
|
| 149 |
cursor: pointer;
|
| 150 |
transition: background-color 0.3s;
|
|
|
|
| 168 |
border-top-left-radius: 0;
|
| 169 |
border-bottom-left-radius: 0;
|
| 170 |
}
|
| 171 |
+
|
| 172 |
+
@media (min-width: 640px) {
|
| 173 |
+
.container {
|
| 174 |
+
max-width: 640px;
|
| 175 |
+
padding: 1.5rem;
|
| 176 |
+
}
|
| 177 |
+
.title {
|
| 178 |
+
font-size: 1.75rem;
|
| 179 |
+
}
|
| 180 |
+
.paper-item h3 {
|
| 181 |
+
font-size: 1.125rem;
|
| 182 |
+
}
|
| 183 |
+
.paper-meta {
|
| 184 |
+
font-size: 0.875rem;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
@media (min-width: 768px) {
|
| 189 |
+
.container {
|
| 190 |
+
max-width: 768px;
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
"""
|
| 194 |
|
| 195 |
paper_manager = PaperManager()
|
|
|
|
| 210 |
|
| 211 |
with demo:
|
| 212 |
with gr.Column(elem_classes=["container"]):
|
| 213 |
+
gr.Markdown("# Daily Papers", elem_classes=["title"])
|
| 214 |
with gr.Row(elem_classes=["search-row"]):
|
| 215 |
+
search_input = gr.Textbox(label="", placeholder="Search papers...")
|
| 216 |
+
refresh_button = gr.Button("↻", variant="primary")
|
| 217 |
paper_list = gr.HTML(elem_classes=["paper-list"])
|
| 218 |
|
| 219 |
with gr.Row(elem_classes=["footer"]):
|
| 220 |
+
prev_button = gr.Button("← Prev")
|
| 221 |
page_info = gr.Markdown()
|
| 222 |
+
next_button = gr.Button("Next →")
|
| 223 |
|
| 224 |
demo.load(initialize_app, outputs=[paper_list, page_info])
|
| 225 |
search_input.change(paper_manager.search_papers, inputs=[search_input], outputs=[paper_list])
|