forked from Dingry/BunnyVisionPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_data.py
More file actions
74 lines (61 loc) · 2.2 KB
/
Copy pathload_data.py
File metadata and controls
74 lines (61 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# import pickle
# from flask import Flask, jsonify, send_file
# import sys
# # Function to load the pickle file
# def load_pkl_file(file_path):
# with open(file_path, 'rb') as f:
# data = pickle.load(f)
# return data
# # Initialize Flask app
# app = Flask(__name__)
# # Define route to serve the data
# @app.route('/data', methods=['GET'])
# def get_data():
# try:
# # Change the file path to your .pkl file
# file_path = 'test_stream.pkl'
# data = load_pkl_file(file_path)
# return jsonify(data) # Serves the data as JSON
# except Exception as e:
# return jsonify({"error": str(e)})
# # Run the app
# if __name__ == '__main__':
# # Set the IP and port (replace with your desired values)
# ip_address = "127.0.0.1" # Change to specific IP if needed
# port = 5000
# # Run the app on the specified IP and port
# app.run(host=ip_address, port=port, debug=True)
import pickle
import time
def load_pkl_file(file_path):
"""Load a pickle (.pkl) file."""
with open(file_path, 'rb') as f:
data = pickle.load(f)
return data
def play_pkl_data(data, delay=1):
"""
"Play" the loaded pickle data.
Assumes data is a list of items to display sequentially.
Args:
data: Sequential data (e.g., list of frames or time series data).
delay: Time in seconds between frames (default: 1 second).
"""
if isinstance(data, list):
# If the data is a list, iterate over it
for index, item in enumerate(data):
print(f"Frame {index + 1}: {item}")
time.sleep(delay) # Wait for the specified delay time
elif isinstance(data, dict):
# If the data is a dictionary, iterate over its items
for key, value in data.items():
print(f"Key: {key}, Value: {value}")
time.sleep(delay) # Wait for the specified delay time
else:
print("Data format not recognized for playback.")
if __name__ == "__main__":
# Specify the path to your .pkl file
file_path = 'test_stream.pkl'
# Load the pickle file
data = load_pkl_file(file_path)
# Play the data with a delay of 1 second between items
play_pkl_data(data, delay=1)