Spaces:
Running
Running
Shiyu Zhao
commited on
Commit
·
57490f5
1
Parent(s):
5bc3f73
Update space
Browse files
app.py
CHANGED
@@ -26,8 +26,6 @@ from stark_qa.evaluator import Evaluator
|
|
26 |
from utils.hub_storage import HubStorage
|
27 |
from utils.token_handler import TokenHandler
|
28 |
|
29 |
-
from forum import ForumPost, SubmissionForum
|
30 |
-
|
31 |
|
32 |
from stark_qa import load_qa
|
33 |
from stark_qa.evaluator import Evaluator
|
@@ -35,9 +33,82 @@ from stark_qa.evaluator import Evaluator
|
|
35 |
from utils.hub_storage import HubStorage
|
36 |
from utils.token_handler import TokenHandler
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# Initialize storage once at startup
|
43 |
try:
|
|
|
26 |
from utils.hub_storage import HubStorage
|
27 |
from utils.token_handler import TokenHandler
|
28 |
|
|
|
|
|
29 |
|
30 |
from stark_qa import load_qa
|
31 |
from stark_qa.evaluator import Evaluator
|
|
|
33 |
from utils.hub_storage import HubStorage
|
34 |
from utils.token_handler import TokenHandler
|
35 |
|
36 |
+
class ForumPost:
|
37 |
+
def __init__(self, message: str, timestamp: str, post_type: str):
|
38 |
+
self.message = message
|
39 |
+
self.timestamp = timestamp
|
40 |
+
self.post_type = post_type # 'submission' or 'status_update'
|
41 |
+
|
42 |
+
class SubmissionForum:
|
43 |
+
def __init__(self, forum_file="forum_posts.json"):
|
44 |
+
self.forum_file = forum_file
|
45 |
+
self.posts = self._load_posts()
|
46 |
+
|
47 |
+
def _load_posts(self):
|
48 |
+
"""Load existing posts from JSON file"""
|
49 |
+
try:
|
50 |
+
with open(self.forum_file, 'r') as f:
|
51 |
+
posts_data = json.load(f)
|
52 |
+
return [ForumPost(**post) for post in posts_data]
|
53 |
+
except FileNotFoundError:
|
54 |
+
return []
|
55 |
+
except Exception as e:
|
56 |
+
print(f"Error loading forum posts: {e}")
|
57 |
+
return []
|
58 |
+
|
59 |
+
def _save_posts(self):
|
60 |
+
"""Save posts to JSON file"""
|
61 |
+
try:
|
62 |
+
posts_data = [
|
63 |
+
{
|
64 |
+
"message": post.message,
|
65 |
+
"timestamp": post.timestamp,
|
66 |
+
"post_type": post.post_type
|
67 |
+
}
|
68 |
+
for post in self.posts
|
69 |
+
]
|
70 |
+
with open(self.forum_file, 'w') as f:
|
71 |
+
json.dump(posts_data, f, indent=4)
|
72 |
+
except Exception as e:
|
73 |
+
print(f"Error saving forum posts: {e}")
|
74 |
+
|
75 |
+
def add_submission_post(self, method_name: str, dataset: str, split: str):
|
76 |
+
"""Add a new submission post"""
|
77 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
78 |
+
message = f"📥 New submission: {method_name} on {split}/{dataset}"
|
79 |
+
self.posts.append(ForumPost(message, timestamp, "submission"))
|
80 |
+
self._save_posts()
|
81 |
+
|
82 |
+
def add_status_update(self, method_name: str, new_status: str):
|
83 |
+
"""Add a status update post"""
|
84 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
85 |
+
emoji = "✅" if new_status == "approved" else "❌"
|
86 |
+
message = f"{emoji} Status update: {method_name} has been {new_status}"
|
87 |
+
self.posts.append(ForumPost(message, timestamp, "status_update"))
|
88 |
+
self._save_posts()
|
89 |
+
|
90 |
+
def get_recent_posts(self, limit=50):
|
91 |
+
"""Get recent posts, newest first"""
|
92 |
+
return sorted(
|
93 |
+
self.posts,
|
94 |
+
key=lambda x: datetime.strptime(x.timestamp, "%Y-%m-%d %H:%M:%S"),
|
95 |
+
reverse=True
|
96 |
+
)[:limit]
|
97 |
+
|
98 |
+
def format_posts_for_display(self, limit=50):
|
99 |
+
"""Format posts for Gradio Markdown display"""
|
100 |
+
recent_posts = self.get_recent_posts(limit)
|
101 |
+
if not recent_posts:
|
102 |
+
return "No forum posts yet."
|
103 |
+
|
104 |
+
formatted_posts = []
|
105 |
+
for post in recent_posts:
|
106 |
+
formatted_posts.append(
|
107 |
+
f"**{post.timestamp}** \n"
|
108 |
+
f"{post.message} \n"
|
109 |
+
f"{'---'}"
|
110 |
+
)
|
111 |
+
return "\n\n".join(formatted_posts)
|
112 |
|
113 |
# Initialize storage once at startup
|
114 |
try:
|