Spaces:
Sleeping
Sleeping
import requests | |
from bs4 import BeautifulSoup | |
import pandas as pd | |
import gradio as gr | |
import time | |
import os | |
import json | |
# ... (keep all the previous functions unchanged) | |
def update_display(category): | |
cache_file = f"{category}_papers_cache.json" | |
url = f"https://paperswithcode.com/{category}" if category != "top" else "https://paperswithcode.com/" | |
data = load_and_cache_data(url, cache_file) | |
df = format_dataframe(data) | |
return len(df), df.to_html(escape=False, index=False) | |
def load_all_data(): | |
top_count, top_html = update_display("top") | |
new_count, new_html = update_display("latest") | |
greatest_count, greatest_html = update_display("greatest") | |
return top_count, top_html, new_count, new_html, greatest_count, greatest_html | |
with gr.Blocks() as demo: | |
gr.Markdown("<h1><center>Papers Leaderboard</center></h1>") | |
with gr.Tab("Top Trending Papers"): | |
top_count = gr.Textbox(label="Number of Papers Fetched") | |
top_html = gr.HTML() | |
top_button = gr.Button("Refresh Leaderboard") | |
top_button.click(fn=lambda: update_display("top"), inputs=None, outputs=[top_count, top_html]) | |
with gr.Tab("New Papers"): | |
new_count = gr.Textbox(label="Number of Papers Fetched") | |
new_html = gr.HTML() | |
new_button = gr.Button("Refresh Leaderboard") | |
new_button.click(fn=lambda: update_display("latest"), inputs=None, outputs=[new_count, new_html]) | |
with gr.Tab("Greatest Papers"): | |
greatest_count = gr.Textbox(label="Number of Papers Fetched") | |
greatest_html = gr.HTML() | |
greatest_button = gr.Button("Refresh Leaderboard") | |
greatest_button.click(fn=lambda: update_display("greatest"), inputs=None, outputs=[greatest_count, greatest_html]) | |
# Load initial data for all tabs | |
demo.load(fn=load_all_data, outputs=[top_count, top_html, new_count, new_html, greatest_count, greatest_html]) | |
# Launch the Gradio interface | |
demo.launch() | |