examples: add start_ui_example.py
This commit is contained in:
parent
14c3d30853
commit
88ac0fc46c
1 changed files with 53 additions and 0 deletions
53
examples/start_ui_example.py
Normal file
53
examples/start_ui_example.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Example showing how to use cognee.start_ui() to launch the frontend.
|
||||||
|
|
||||||
|
This demonstrates the new UI functionality that works similar to DuckDB's start_ui().
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import cognee
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
# First, let's add some data to cognee for the UI to display
|
||||||
|
print("Adding sample data to cognee...")
|
||||||
|
await cognee.add("Natural language processing (NLP) is an interdisciplinary subfield of computer science and information retrieval.")
|
||||||
|
await cognee.add("Machine learning (ML) is a subset of artificial intelligence that focuses on algorithms and statistical models.")
|
||||||
|
|
||||||
|
# Generate the knowledge graph
|
||||||
|
print("Generating knowledge graph...")
|
||||||
|
await cognee.cognify()
|
||||||
|
|
||||||
|
print("\n" + "="*60)
|
||||||
|
print("Starting cognee UI...")
|
||||||
|
print("="*60)
|
||||||
|
|
||||||
|
# Start the UI server
|
||||||
|
server = cognee.start_ui(
|
||||||
|
host="localhost",
|
||||||
|
port=3000,
|
||||||
|
open_browser=True # This will automatically open your browser
|
||||||
|
)
|
||||||
|
|
||||||
|
if server:
|
||||||
|
print("UI server started successfully!")
|
||||||
|
print("The interface will be available at: http://localhost:3000")
|
||||||
|
print("\nPress Ctrl+C to stop the server when you're done...")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Keep the server running
|
||||||
|
while server.poll() is None: # While process is still running
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nStopping UI server...")
|
||||||
|
server.terminate()
|
||||||
|
server.wait() # Wait for process to finish
|
||||||
|
print("UI server stopped.")
|
||||||
|
else:
|
||||||
|
print("Failed to start UI server. Check the logs above for details.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Loading…
Add table
Reference in a new issue