YixuanWang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -129,6 +129,7 @@ class RecommendationSystem:
|
|
129 |
"热度": "基于点赞和转发的热度分数"
|
130 |
}
|
131 |
|
|
|
132 |
def create_gradio_interface(recommendation_system: RecommendationSystem) -> gr.Interface:
|
133 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
134 |
gr.Markdown("""
|
@@ -156,14 +157,31 @@ def create_gradio_interface(recommendation_system: RecommendationSystem) -> gr.I
|
|
156 |
submit_btn = gr.Button("获取推荐", variant="primary")
|
157 |
|
158 |
with gr.Column(scale=2):
|
159 |
-
|
|
|
|
|
|
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
submit_btn.click(
|
162 |
-
fn=lambda v, s, p:
|
163 |
-
RecommendationWeights(v, s, p)
|
164 |
),
|
165 |
inputs=[visibility_weight, sentiment_weight, popularity_weight],
|
166 |
-
outputs=
|
167 |
)
|
168 |
|
169 |
return interface
|
|
|
129 |
"热度": "基于点赞和转发的热度分数"
|
130 |
}
|
131 |
|
132 |
+
|
133 |
def create_gradio_interface(recommendation_system: RecommendationSystem) -> gr.Interface:
|
134 |
with gr.Blocks(theme=gr.themes.Soft()) as interface:
|
135 |
gr.Markdown("""
|
|
|
157 |
submit_btn = gr.Button("获取推荐", variant="primary")
|
158 |
|
159 |
with gr.Column(scale=2):
|
160 |
+
results = gr.Dataframe(
|
161 |
+
headers=["推文内容", "评分详情"],
|
162 |
+
label="推荐结果"
|
163 |
+
)
|
164 |
|
165 |
+
def format_for_display(recommendations):
|
166 |
+
rows = []
|
167 |
+
for rec in recommendations["recommendations"]:
|
168 |
+
scores = rec["scores"]
|
169 |
+
score_text = (
|
170 |
+
f"总分: {scores['总分']}\n"
|
171 |
+
f"可信度: {scores['可信度']}\n"
|
172 |
+
f"情感倾向: {scores['情感倾向']}\n"
|
173 |
+
f"热度: {scores['热度']}\n"
|
174 |
+
f"互动: {scores['互动数']}"
|
175 |
+
)
|
176 |
+
rows.append([rec["text"], score_text])
|
177 |
+
return rows
|
178 |
+
|
179 |
submit_btn.click(
|
180 |
+
fn=lambda v, s, p: format_for_display(
|
181 |
+
recommendation_system.get_recommendations(RecommendationWeights(v, s, p))
|
182 |
),
|
183 |
inputs=[visibility_weight, sentiment_weight, popularity_weight],
|
184 |
+
outputs=results
|
185 |
)
|
186 |
|
187 |
return interface
|