linbojunzi commited on
Commit
4adc9d4
·
verified ·
1 Parent(s): f11abe4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -23
app.py CHANGED
@@ -35,32 +35,49 @@ with open("gpt4o_50.json", "r") as file:
35
 
36
  st.title("JSON Data Visualization")
37
 
38
- columns_per_row = 4
39
- columns = st.columns(columns_per_row)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- # 用于存储每列的内容高度
42
- heights = [0] * columns_per_row
43
- content_list = [[] for _ in range(columns_per_row)] # 每列内容占位
44
-
45
- # 遍历数据并将内容分配到列
46
- for idx, (qwen, gpt) in enumerate(zip(qwen_data, gpt_data)):
47
  image_name, image_url, description, qwen_category = qwen
48
  _, _, _, gpt_category = gpt
49
 
50
- # 将内容添加到对应列的内容列表中
51
- col_idx = idx % columns_per_row
52
  content = f"""
53
- ### {image_name}
54
- ![]({image_url})
55
- **Description:** {description}
56
- **Qwen_Category:** {qwen_category}
57
- **GPT_Category:** {gpt_category}
58
- ---
 
 
 
59
  """
60
- content_list[col_idx].append(content)
61
-
62
- # 渲染每列内容
63
- for col_idx, col_content in enumerate(content_list):
64
- with columns[col_idx]:
65
- for item in col_content:
66
- st.markdown(item)
 
35
 
36
  st.title("JSON Data Visualization")
37
 
38
+ # 定义 CSS 样式
39
+ st.markdown("""
40
+ <style>
41
+ .row {
42
+ display: flex;
43
+ flex-wrap: wrap;
44
+ justify-content: space-between;
45
+ }
46
+ .column {
47
+ flex: 1 1 calc(25% - 20px); /* 固定为 4 列,每列占 25% 减去间距 */
48
+ max-width: calc(25% - 20px);
49
+ margin: 10px;
50
+ box-sizing: border-box;
51
+ }
52
+ .content {
53
+ height: 100%;
54
+ display: flex;
55
+ flex-direction: column;
56
+ justify-content: space-between;
57
+ background-color: #f9f9f9;
58
+ padding: 10px;
59
+ border: 1px solid #ddd;
60
+ border-radius: 5px;
61
+ }
62
+ </style>
63
+ """, unsafe_allow_html=True)
64
 
65
+ # 渲染内容
66
+ st.markdown('<div class="row">', unsafe_allow_html=True)
67
+ for qwen, gpt in zip(qwen_data, gpt_data):
 
 
 
68
  image_name, image_url, description, qwen_category = qwen
69
  _, _, _, gpt_category = gpt
70
 
 
 
71
  content = f"""
72
+ <div class="column">
73
+ <div class="content">
74
+ <h4>{image_name}</h4>
75
+ <img src="{image_url}" style="width:100%;" alt="{description}">
76
+ <p><strong>Description:</strong> {description}</p>
77
+ <p><strong>Qwen_Category:</strong> {qwen_category}</p>
78
+ <p><strong>GPT_Category:</strong> {gpt_category}</p>
79
+ </div>
80
+ </div>
81
  """
82
+ st.markdown(content, unsafe_allow_html=True)
83
+ st.markdown('</div>', unsafe_allow_html=True)