Update app.py
Browse files
app.py
CHANGED
@@ -19,9 +19,7 @@ from llama_index.llms.openai import OpenAI
|
|
19 |
from llama_index.embeddings.openai import OpenAIEmbedding
|
20 |
from llama_index.core import Settings
|
21 |
|
22 |
-
import openai
|
23 |
import os
|
24 |
-
from github import Github
|
25 |
from datetime import datetime
|
26 |
import gradio as gr
|
27 |
import pandas as pd
|
@@ -34,38 +32,49 @@ exec(os.environ.get('context'))
|
|
34 |
|
35 |
|
36 |
##### Graph start ##########
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
from io import BytesIO
|
41 |
|
42 |
def draw_graph():
|
43 |
global kg_data
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
for source, relation, target in kg_data:
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
#
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
##### Graph end ##########
|
70 |
|
71 |
|
@@ -716,7 +725,7 @@ with gr.Blocks(theme='sudeepshouche/minimalist', css=css) as demo:
|
|
716 |
""")
|
717 |
|
718 |
with gr.Row():
|
719 |
-
grafo = gr.
|
720 |
|
721 |
with gr.Accordion(elem_classes="accordion", label="Audit trail", open=False):
|
722 |
with gr.Row():
|
|
|
19 |
from llama_index.embeddings.openai import OpenAIEmbedding
|
20 |
from llama_index.core import Settings
|
21 |
|
|
|
22 |
import os
|
|
|
23 |
from datetime import datetime
|
24 |
import gradio as gr
|
25 |
import pandas as pd
|
|
|
32 |
|
33 |
|
34 |
##### Graph start ##########
|
35 |
+
from pyvis.network import Network
|
36 |
+
from io import StringIO
|
37 |
+
import html
|
|
|
38 |
|
39 |
def draw_graph():
|
40 |
global kg_data
|
41 |
+
|
42 |
+
# Crear un grafo con opciones visuales b谩sicas
|
43 |
+
net = Network(
|
44 |
+
notebook=True,
|
45 |
+
height="700px",
|
46 |
+
width="100%",
|
47 |
+
select_menu=True,
|
48 |
+
neighborhood_highlight=True,
|
49 |
+
cdn_resources="remote"
|
50 |
+
)
|
51 |
+
|
52 |
+
# A帽adir nodos y relaciones desde los datos del grafo
|
53 |
for source, relation, target in kg_data:
|
54 |
+
# Agregar nodos
|
55 |
+
net.add_node(source, label=source, color="skyblue")
|
56 |
+
net.add_node(target, label=target, color="skyblue")
|
57 |
+
# Agregar aristas con la relaci贸n como etiqueta
|
58 |
+
net.add_edge(source, target, title=relation, label=relation, color="black")
|
59 |
+
|
60 |
+
# Generar el HTML como string
|
61 |
+
html_output = StringIO()
|
62 |
+
net.write_html(html_output)
|
63 |
+
html_output.seek(0)
|
64 |
+
html_contenido = html_output.getvalue()
|
65 |
+
|
66 |
+
# Generar el iframe embebido
|
67 |
+
return generar_iframe_embebido(html_contenido)
|
68 |
+
|
69 |
+
def generar_iframe_embebido(html_contenido):
|
70 |
+
# Escapar el contenido HTML para que sea seguro dentro del atributo srcdoc
|
71 |
+
html_escapado = html.escape(html_contenido)
|
72 |
+
|
73 |
+
# Generar el string del iframe con el contenido embebido
|
74 |
+
iframe = f"""
|
75 |
+
<iframe srcdoc="{html_escapado}" width="100%" height="700px" style="border:none;"></iframe>
|
76 |
+
"""
|
77 |
+
return iframe
|
78 |
##### Graph end ##########
|
79 |
|
80 |
|
|
|
725 |
""")
|
726 |
|
727 |
with gr.Row():
|
728 |
+
grafo = gr.HTML(label="Grafo", show_share_button=False)
|
729 |
|
730 |
with gr.Accordion(elem_classes="accordion", label="Audit trail", open=False):
|
731 |
with gr.Row():
|