stzhao commited on
Commit
7db628a
·
verified ·
1 Parent(s): d1d4aa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -51,7 +51,7 @@ def process_message(file_path):
51
  messages = json.load(f)
52
 
53
  # 创建HTML输出
54
- html_output = ""
55
 
56
  for message_item in messages:
57
  role = message_item['role']
@@ -59,11 +59,11 @@ def process_message(file_path):
59
 
60
  # 根据角色设置样式
61
  if role == "user" or role == "human":
62
- html_output += f'<div style="background-color: #f0f0f0; padding: 10px; margin: 10px 0; border-radius: 10px;"><strong>User:</strong><br>'
63
  elif role == "assistant":
64
- html_output += f'<div style="background-color: #e6f7ff; padding: 10px; margin: 10px 0; border-radius: 10px;"><strong>Assistant:</strong><br>'
65
  else:
66
- html_output += f'<div style="background-color: #f9f9f9; padding: 10px; margin: 10px 0; border-radius: 10px;"><strong>{role.capitalize()}:</strong><br>'
67
 
68
  # 处理内容
69
  for content_item in content:
@@ -73,7 +73,7 @@ def process_message(file_path):
73
  # 将Markdown文本转换为HTML
74
  md_text = content_item['text']
75
  html_text = markdown.markdown(md_text, extensions=['fenced_code', 'codehilite'])
76
- html_output += html_text
77
 
78
  elif content_type == "image_url":
79
  content_value = content_item['image_url']['url']
@@ -85,6 +85,7 @@ def process_message(file_path):
85
 
86
  html_output += '</div>'
87
 
 
88
  return html_output
89
 
90
  except Exception as e:
@@ -137,7 +138,7 @@ def setup_example_file():
137
  setup_example_file()
138
 
139
  # 创建Gradio界面
140
- with gr.Blocks(title="ChatGPT Conversation Visualizer") as demo:
141
  gr.Markdown("# ChatGPT 对话可视化工具")
142
  gr.Markdown("上传一个包含ChatGPT对话记录的JSON文件,或使用示例文件查看可视化结果")
143
 
 
51
  messages = json.load(f)
52
 
53
  # 创建HTML输出
54
+ html_output = '<div style="color: black;">' # 添加一个包裹所有内容的div,设置文本颜色为黑色
55
 
56
  for message_item in messages:
57
  role = message_item['role']
 
59
 
60
  # 根据角色设置样式
61
  if role == "user" or role == "human":
62
+ html_output += f'<div style="background-color: #f0f0f0; padding: 10px; margin: 10px 0; border-radius: 10px; color: black;"><strong>User:</strong><br>'
63
  elif role == "assistant":
64
+ html_output += f'<div style="background-color: #e6f7ff; padding: 10px; margin: 10px 0; border-radius: 10px; color: black;"><strong>Assistant:</strong><br>'
65
  else:
66
+ html_output += f'<div style="background-color: #f9f9f9; padding: 10px; margin: 10px 0; border-radius: 10px; color: black;"><strong>{role.capitalize()}:</strong><br>'
67
 
68
  # 处理内容
69
  for content_item in content:
 
73
  # 将Markdown文本转换为HTML
74
  md_text = content_item['text']
75
  html_text = markdown.markdown(md_text, extensions=['fenced_code', 'codehilite'])
76
+ html_output += f'<div style="color: black;">{html_text}</div>'
77
 
78
  elif content_type == "image_url":
79
  content_value = content_item['image_url']['url']
 
85
 
86
  html_output += '</div>'
87
 
88
+ html_output += '</div>' # 关闭最外层div
89
  return html_output
90
 
91
  except Exception as e:
 
138
  setup_example_file()
139
 
140
  # 创建Gradio界面
141
+ with gr.Blocks(title="ChatGPT Conversation Visualizer", css="div.prose * {color: black !important;}") as demo:
142
  gr.Markdown("# ChatGPT 对话可视化工具")
143
  gr.Markdown("上传一个包含ChatGPT对话记录的JSON文件,或使用示例文件查看可视化结果")
144