knowledge graph
Browse files- app.py +1 -1
- knowledge.py +2 -19
app.py
CHANGED
|
@@ -132,7 +132,7 @@ Low APR and great customer service. I would highly recommend if you’re looking
|
|
| 132 |
================================================
|
| 133 |
""")
|
| 134 |
in_verbatim = gr.Textbox(label="Question")
|
| 135 |
-
out_product = gr.
|
| 136 |
|
| 137 |
gr.Examples(
|
| 138 |
[
|
|
|
|
| 132 |
================================================
|
| 133 |
""")
|
| 134 |
in_verbatim = gr.Textbox(label="Question")
|
| 135 |
+
out_product = gr.JSON(label="Knowledge Graph")
|
| 136 |
|
| 137 |
gr.Examples(
|
| 138 |
[
|
knowledge.py
CHANGED
|
@@ -49,7 +49,7 @@ client = instructor.from_openai(
|
|
| 49 |
"""
|
| 50 |
def generate_graph(input) -> KnowledgeGraph:
|
| 51 |
return client.chat.completions.create(
|
| 52 |
-
model='llama-3.1-8b-instant', #"llama3.2",
|
| 53 |
max_retries=5,
|
| 54 |
messages=[
|
| 55 |
{
|
|
@@ -59,23 +59,6 @@ def generate_graph(input) -> KnowledgeGraph:
|
|
| 59 |
],
|
| 60 |
response_model=KnowledgeGraph,
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
def visualize_knowledge_graph(kg: KnowledgeGraph):
|
| 65 |
-
dot = Digraph(comment="Knowledge Graph")
|
| 66 |
-
|
| 67 |
-
# Add nodes
|
| 68 |
-
for node in kg.nodes:
|
| 69 |
-
dot.node(str(node.id), node.label, color=node.color)
|
| 70 |
-
|
| 71 |
-
# Add edges
|
| 72 |
-
for edge in kg.edges:
|
| 73 |
-
dot.edge(str(edge.source), str(edge.target), label=edge.label, color=edge.color)
|
| 74 |
-
|
| 75 |
-
# Render the graph
|
| 76 |
-
dot.render("/tmp/knowledge_graph", format="png")
|
| 77 |
-
|
| 78 |
def graph(query):
|
| 79 |
graph = generate_graph(query)
|
| 80 |
-
|
| 81 |
-
return "/tmp/knowledge_graph.png"
|
|
|
|
| 49 |
"""
|
| 50 |
def generate_graph(input) -> KnowledgeGraph:
|
| 51 |
return client.chat.completions.create(
|
| 52 |
+
model='llama-3.1-8b-instant', #"llama3.2", #
|
| 53 |
max_retries=5,
|
| 54 |
messages=[
|
| 55 |
{
|
|
|
|
| 59 |
],
|
| 60 |
response_model=KnowledgeGraph,
|
| 61 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def graph(query):
|
| 63 |
graph = generate_graph(query)
|
| 64 |
+
return graph.json()
|
|
|