Spaces:
Sleeping
Sleeping
| import sys, os | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) | |
| from FrameProcessor.graph.workflow import frame_processor | |
| from types_.state import GraphState | |
| from PIL import Image | |
| import io | |
| import base64 | |
| def load_image_base64(image_path): | |
| """Load image and return base64 string""" | |
| with open(image_path, "rb") as img_file: | |
| return base64.b64encode(img_file.read()).decode("utf-8") | |
| def test_graph_on_frame(frame_path): | |
| if not os.path.exists(frame_path): | |
| raise FileNotFoundError(f"Frame not found: {frame_path}") | |
| base64_img = load_image_base64(frame_path) | |
| # Initial graph state | |
| initial_state: GraphState = { | |
| "frame_path": frame_path, | |
| "frame_data": { | |
| "base64_image": base64_img, | |
| }, | |
| "frame_features": {}, | |
| "importance": "not_important", | |
| "reason": "", | |
| "description": {}, | |
| "next_step": "extract_features" | |
| } | |
| # Run the graph | |
| final_state = frame_processor.invoke(initial_state) | |
| # Print summary | |
| print("\n=== Graph Result ===") | |
| for k, v in final_state.items(): | |
| if isinstance(v, dict): | |
| print(f"{k}: dict with {len(v)} keys") | |
| elif isinstance(v, list): | |
| print(f"{k}: list with {len(v)} items") | |
| else: | |
| print(f"{k}: {v}") | |
| if __name__ == "__main__": | |
| # 👇 Replace this with any valid image path | |
| test_graph_on_frame("/home/israa/Desktop/SummerAIse/outputs/keyframes/keyframe_0000.jpg") | |