Spaces:
Running
Running
deploy at 2024-09-05 17:01:27.543501
Browse files
app.py
CHANGED
@@ -21,9 +21,14 @@ gridlink = Link(
|
|
21 |
href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css",
|
22 |
type="text/css",
|
23 |
)
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Our FastHTML app
|
26 |
-
app = FastHTML(hdrs=(picolink, gridlink))
|
27 |
|
28 |
|
29 |
def make_card(c):
|
@@ -45,11 +50,24 @@ def make_card(c):
|
|
45 |
def home():
|
46 |
|
47 |
return Div(
|
48 |
-
Div(
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
cls="container",
|
51 |
)
|
52 |
|
|
|
53 |
@app.get("/refresh")
|
54 |
def refresh():
|
55 |
recent = all_comments(order_by="date DESC", limit=20)
|
@@ -59,9 +77,10 @@ def refresh():
|
|
59 |
id="cards",
|
60 |
)
|
61 |
|
|
|
62 |
@app.get("/focus/{id}")
|
63 |
def focus_one_comment(id):
|
64 |
-
|
65 |
discussion = hf_api.get_discussion_details()
|
66 |
|
67 |
|
@@ -83,7 +102,11 @@ async def hf_webhook(request):
|
|
83 |
print("Invalid secret")
|
84 |
return {"error": "Invalid secret"}, 400
|
85 |
|
86 |
-
if
|
|
|
|
|
|
|
|
|
87 |
title = payload["discussion"]["title"]
|
88 |
comment = payload["comment"].get("content", "")
|
89 |
if "url" not in payload["comment"]:
|
@@ -111,7 +134,11 @@ def check_for_inference_help(comment):
|
|
111 |
return any(phrase in comment.lower() for phrase in common_phrases)
|
112 |
|
113 |
|
114 |
-
|
115 |
setup_hf_backup(app)
|
|
|
|
|
|
|
|
|
116 |
|
117 |
uvicorn.run("main:app", host="0.0.0.0", port=int(os.getenv("PORT", default=7860)))
|
|
|
21 |
href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css",
|
22 |
type="text/css",
|
23 |
)
|
24 |
+
css = Link(
|
25 |
+
rel="stylesheet",
|
26 |
+
href="style.css",
|
27 |
+
type="text/css",
|
28 |
+
)
|
29 |
|
30 |
# Our FastHTML app
|
31 |
+
app = FastHTML(hdrs=(picolink, gridlink, css))
|
32 |
|
33 |
|
34 |
def make_card(c):
|
|
|
50 |
def home():
|
51 |
|
52 |
return Div(
|
53 |
+
Div(
|
54 |
+
Button(
|
55 |
+
"Refresh", hx_get=("/refresh"), hx_swap="outerHTML", target_id="cards"
|
56 |
+
),
|
57 |
+
cls="row",
|
58 |
+
id="top-bar",
|
59 |
+
),
|
60 |
+
Div(
|
61 |
+
"Loading...",
|
62 |
+
id="cards",
|
63 |
+
hx_get="/refresh",
|
64 |
+
hx_trigger="every 1s",
|
65 |
+
hx_swap="outerHTML",
|
66 |
+
),
|
67 |
cls="container",
|
68 |
)
|
69 |
|
70 |
+
|
71 |
@app.get("/refresh")
|
72 |
def refresh():
|
73 |
recent = all_comments(order_by="date DESC", limit=20)
|
|
|
77 |
id="cards",
|
78 |
)
|
79 |
|
80 |
+
|
81 |
@app.get("/focus/{id}")
|
82 |
def focus_one_comment(id):
|
83 |
+
|
84 |
discussion = hf_api.get_discussion_details()
|
85 |
|
86 |
|
|
|
102 |
print("Invalid secret")
|
103 |
return {"error": "Invalid secret"}, 400
|
104 |
|
105 |
+
if (
|
106 |
+
payload["repo"]["type"] == "model"
|
107 |
+
and "comment" in payload
|
108 |
+
and payload["comment"] is not None
|
109 |
+
):
|
110 |
title = payload["discussion"]["title"]
|
111 |
comment = payload["comment"].get("content", "")
|
112 |
if "url" not in payload["comment"]:
|
|
|
134 |
return any(phrase in comment.lower() for phrase in common_phrases)
|
135 |
|
136 |
|
137 |
+
try:
|
138 |
setup_hf_backup(app)
|
139 |
+
except Exception as e:
|
140 |
+
print("Could not setup backup", e)
|
141 |
+
|
142 |
+
if __name__ == "__main__":
|
143 |
|
144 |
uvicorn.run("main:app", host="0.0.0.0", port=int(os.getenv("PORT", default=7860)))
|
style.css
CHANGED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#top-bar {
|
2 |
+
display: flex;
|
3 |
+
justify-content: space-between;
|
4 |
+
align-items: center;
|
5 |
+
margin-bottom: 10px;
|
6 |
+
}
|