deven367 commited on
Commit
b97f55d
Β·
1 Parent(s): 8abf36a

upload json files

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -18
src/streamlit_app.py CHANGED
@@ -7,10 +7,9 @@ import streamlit as st
7
  st.set_page_config(page_title="Conversation Viewer", layout="wide")
8
 
9
  @st.cache_data
10
- def load_conversations(file_path):
11
- """Load conversations from JSON file"""
12
- with open(file_path, 'r', encoding='utf-8') as f:
13
- return json.load(f)
14
 
15
  def format_timestamp(timestamp):
16
  """Convert timestamp to readable format"""
@@ -18,7 +17,7 @@ def format_timestamp(timestamp):
18
  if timestamp > 1e12: # milliseconds
19
  timestamp = timestamp / 1000
20
  return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
21
- except:
22
  return "N/A"
23
 
24
  def search_in_conversation(conv, search_term):
@@ -57,14 +56,12 @@ def display_message(msg):
57
  def main():
58
  st.title("πŸ’¬ Conversation Viewer")
59
 
60
- # File selector
61
- json_file = st.text_input(
62
- "JSON File Path",
63
- value="conversations_2025-11-01.json",
64
- help="Enter the path to your conversations JSON file"
65
- )
66
-
67
 
 
 
 
68
 
69
  try:
70
  conversations = load_conversations(json_file)
@@ -122,7 +119,6 @@ def main():
122
 
123
  # Display conversation details
124
  # have a border around this box
125
- st.markdown(f"<div style='border: 1px solid #eee; padding: 10px; border-radius: 5px;'>", unsafe_allow_html=True)
126
  st.write(selected_conv['conv']['name'])
127
 
128
  col1, col2, col3 = st.columns(3)
@@ -144,13 +140,10 @@ def main():
144
  else:
145
  st.info("No conversations found matching your search.")
146
 
147
- except FileNotFoundError:
148
- st.error(f"❌ File not found: {json_file}")
149
- st.info("Please make sure the file path is correct.")
150
  except json.JSONDecodeError:
151
- st.error("❌ Invalid JSON file")
152
  except Exception as e:
153
- st.error(f"❌ Error: {str(e)}")
154
 
155
  if __name__ == "__main__":
156
  main()
 
7
  st.set_page_config(page_title="Conversation Viewer", layout="wide")
8
 
9
  @st.cache_data
10
+ def load_conversations(uploaded_file):
11
+ """Load conversations from uploaded JSON file"""
12
+ return json.load(uploaded_file)
 
13
 
14
  def format_timestamp(timestamp):
15
  """Convert timestamp to readable format"""
 
17
  if timestamp > 1e12: # milliseconds
18
  timestamp = timestamp / 1000
19
  return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
20
+ except Exception:
21
  return "N/A"
22
 
23
  def search_in_conversation(conv, search_term):
 
56
  def main():
57
  st.title("πŸ’¬ Conversation Viewer")
58
 
59
+ # File uploader
60
+ json_file = st.file_uploader("Upload JSON file", type="json")
 
 
 
 
 
61
 
62
+ if json_file is None:
63
+ st.info("πŸ‘† Please upload a JSON file containing your conversations to get started.")
64
+ return
65
 
66
  try:
67
  conversations = load_conversations(json_file)
 
119
 
120
  # Display conversation details
121
  # have a border around this box
 
122
  st.write(selected_conv['conv']['name'])
123
 
124
  col1, col2, col3 = st.columns(3)
 
140
  else:
141
  st.info("No conversations found matching your search.")
142
 
 
 
 
143
  except json.JSONDecodeError:
144
+ st.error("❌ Invalid JSON file format. Please upload a valid JSON file.")
145
  except Exception as e:
146
+ st.error(f"❌ Error loading conversations: {str(e)}")
147
 
148
  if __name__ == "__main__":
149
  main()