Spaces:
Running
Running
Upload 2 files
Browse files- app.py +28 -0
- requirements.txt +4 -2
app.py
CHANGED
|
@@ -18,6 +18,28 @@ from pyvis.network import Network
|
|
| 18 |
import pandas as pd
|
| 19 |
import matplotlib.pyplot as plt
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# 配置日志
|
| 22 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 23 |
|
|
@@ -820,4 +842,10 @@ with gr.Blocks(css="""
|
|
| 820 |
import_output = gr.Textbox(label="导入日志")
|
| 821 |
import_btn.click(fn=lambda: import_dataset(dataset_path.value), outputs=import_output)
|
| 822 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 18 |
import pandas as pd
|
| 19 |
import matplotlib.pyplot as plt
|
| 20 |
|
| 21 |
+
|
| 22 |
+
from gqlalchemy import Memgraph
|
| 23 |
+
import os
|
| 24 |
+
|
| 25 |
+
MEMGRAPH_HOST = '3.76.194.251'
|
| 26 |
+
MEMGRAPH_PORT = 7687
|
| 27 |
+
MEMGRAPH_USERNAME = '[email protected]'
|
| 28 |
+
MEMGRAPH_PASSWORD = os.environ.get("MEMGRAPH_PASSWORD", "<YOUR MEMGRAPH PASSWORD HERE>")
|
| 29 |
+
|
| 30 |
+
def hello_memgraph():
|
| 31 |
+
try:
|
| 32 |
+
connection = Memgraph(MEMGRAPH_HOST, MEMGRAPH_PORT, MEMGRAPH_USERNAME, MEMGRAPH_PASSWORD, encrypted=True)
|
| 33 |
+
results = connection.execute_and_fetch(
|
| 34 |
+
'CREATE (n:FirstNode { message: "Hello Memgraph from Python!" }) RETURN n.message AS message'
|
| 35 |
+
)
|
| 36 |
+
return f"成功创建节点: {next(results)['message']}"
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"连接失败: {str(e)}"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
# 配置日志
|
| 44 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 45 |
|
|
|
|
| 842 |
import_output = gr.Textbox(label="导入日志")
|
| 843 |
import_btn.click(fn=lambda: import_dataset(dataset_path.value), outputs=import_output)
|
| 844 |
|
| 845 |
+
gr.Markdown("### 测试 Memgraph 数据库连接")
|
| 846 |
+
memgraph_btn = gr.Button("测试 Memgraph 连接")
|
| 847 |
+
memgraph_output = gr.Textbox(label="连接测试日志")
|
| 848 |
+
memgraph_btn.click(fn=hello_memgraph, outputs=memgraph_output)
|
| 849 |
+
|
| 850 |
+
|
| 851 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -29,7 +29,9 @@ plotly>=5.10.0
|
|
| 29 |
protobuf>=3.20.0
|
| 30 |
accelerate>=0.20.0
|
| 31 |
|
| 32 |
-
|
| 33 |
# 其他依赖
|
| 34 |
requests>=2.25.0
|
| 35 |
-
beautifulsoup4>=4.10.0
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
protobuf>=3.20.0
|
| 30 |
accelerate>=0.20.0
|
| 31 |
|
|
|
|
| 32 |
# 其他依赖
|
| 33 |
requests>=2.25.0
|
| 34 |
+
beautifulsoup4>=4.10.0
|
| 35 |
+
|
| 36 |
+
# gqlalchemy
|
| 37 |
+
gqlalchemy>=0.3.1
|