artificialguybr commited on
Commit
2fce835
1 Parent(s): 572ad52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -7,6 +7,7 @@ def generate_knowledge_graph(api_key, user_input):
7
  openai.api_key = api_key
8
 
9
  # Chamar a API da OpenAI
 
10
  completion = openai.ChatCompletion.create(
11
  model="gpt-3.5-turbo-16k",
12
  messages=[
@@ -19,7 +20,11 @@ def generate_knowledge_graph(api_key, user_input):
19
  response_data = completion.choices[0].message.to_dict()
20
  response_data = json.loads(response_data['content'])
21
 
 
 
 
22
  # Visualizar o conhecimento usando Graphviz
 
23
  dot = Digraph(comment="Knowledge Graph")
24
  for node in response_data.get("nodes", []):
25
  dot.node(node["id"], f"{node['label']} ({node['type']})")
@@ -27,9 +32,12 @@ def generate_knowledge_graph(api_key, user_input):
27
  dot.edge(edge["from"], edge["to"], label=edge["relationship"])
28
 
29
  # Renderizar para o formato PNG
 
30
  dot.format = "png"
31
  dot.render(filename="knowledge_graph", cleanup=True)
32
 
 
 
33
  return "knowledge_graph.png"
34
 
35
  iface = gr.Interface(
@@ -42,4 +50,5 @@ iface = gr.Interface(
42
  live=False
43
  )
44
 
45
- iface.launch()
 
 
7
  openai.api_key = api_key
8
 
9
  # Chamar a API da OpenAI
10
+ print("Chamando a API da OpenAI...")
11
  completion = openai.ChatCompletion.create(
12
  model="gpt-3.5-turbo-16k",
13
  messages=[
 
20
  response_data = completion.choices[0].message.to_dict()
21
  response_data = json.loads(response_data['content'])
22
 
23
+ print("Dados da resposta:")
24
+ print(response_data)
25
+
26
  # Visualizar o conhecimento usando Graphviz
27
+ print("Gerando o conhecimento usando Graphviz...")
28
  dot = Digraph(comment="Knowledge Graph")
29
  for node in response_data.get("nodes", []):
30
  dot.node(node["id"], f"{node['label']} ({node['type']})")
 
32
  dot.edge(edge["from"], edge["to"], label=edge["relationship"])
33
 
34
  # Renderizar para o formato PNG
35
+ print("Renderizando o gráfico para o formato PNG...")
36
  dot.format = "png"
37
  dot.render(filename="knowledge_graph", cleanup=True)
38
 
39
+ print("Gráfico gerado com sucesso!")
40
+
41
  return "knowledge_graph.png"
42
 
43
  iface = gr.Interface(
 
50
  live=False
51
  )
52
 
53
+ print("Iniciando a interface Gradio...")
54
+ iface.launch()