artificialguybr
commited on
Commit
·
41813c2
1
Parent(s):
9ec289c
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import openai
|
3 |
import json
|
4 |
from graphviz import Digraph
|
|
|
|
|
5 |
|
6 |
def generate_knowledge_graph(api_key, user_input):
|
7 |
openai.api_key = api_key
|
@@ -98,11 +100,12 @@ def generate_knowledge_graph(api_key, user_input):
|
|
98 |
# Renderizar para o formato PNG
|
99 |
print("Renderizando o gráfico para o formato PNG...")
|
100 |
dot.format = "png"
|
101 |
-
dot.
|
|
|
102 |
|
103 |
print("Gráfico gerado com sucesso!")
|
104 |
|
105 |
-
return
|
106 |
|
107 |
iface = gr.Interface(
|
108 |
fn=generate_knowledge_graph,
|
@@ -110,7 +113,7 @@ iface = gr.Interface(
|
|
110 |
gr.inputs.Textbox(label="OpenAI API Key", type="password"),
|
111 |
gr.inputs.Textbox(label="User Input for Graph"),
|
112 |
],
|
113 |
-
outputs=gr.outputs.Image(type="
|
114 |
live=False,
|
115 |
)
|
116 |
|
|
|
2 |
import openai
|
3 |
import json
|
4 |
from graphviz import Digraph
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
|
8 |
def generate_knowledge_graph(api_key, user_input):
|
9 |
openai.api_key = api_key
|
|
|
100 |
# Renderizar para o formato PNG
|
101 |
print("Renderizando o gráfico para o formato PNG...")
|
102 |
dot.format = "png"
|
103 |
+
image_data = dot.pipe(format="png")
|
104 |
+
image = Image.open(io.BytesIO(image_data))
|
105 |
|
106 |
print("Gráfico gerado com sucesso!")
|
107 |
|
108 |
+
return image
|
109 |
|
110 |
iface = gr.Interface(
|
111 |
fn=generate_knowledge_graph,
|
|
|
113 |
gr.inputs.Textbox(label="OpenAI API Key", type="password"),
|
114 |
gr.inputs.Textbox(label="User Input for Graph"),
|
115 |
],
|
116 |
+
outputs=gr.outputs.Image(type="PIL", label="Generated Knowledge Graph"),
|
117 |
live=False,
|
118 |
)
|
119 |
|