helliun commited on
Commit
d6e52e9
·
1 Parent(s): e03fe0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  def generate_graph(input_text,api_key,graph):
6
  if graph == []:
7
  kg = KnowledgeGraph(api_key)
8
- graph[0] = kg
9
  else:
10
  kg = graph[0]
11
  kg.learn(str(input_text))
@@ -14,13 +14,19 @@ def generate_graph(input_text,api_key,graph):
14
  return img,graph
15
 
16
  def answer_question(question,api_key,graph):
17
- if graph[0] =="":
18
  kg = KnowledgeGraph(api_key)
19
- graph[0] = kg
20
  else:
21
  kg = graph[0]
22
  return kg.chat_qa(question)
23
 
 
 
 
 
 
 
24
  title = "GPT-4 Knowledge Graph Generator"
25
  description = "Enter text to generate a knowledge graph using GPT4KG:"
26
 
@@ -39,6 +45,6 @@ with gr.Blocks() as demo:
39
  qa_btn.click(fn=answer_question, inputs=[question,api_key,graph], outputs=[answer])
40
 
41
  clear_btn = gr.Button("Clear graph")
42
- clear_btn.click(lambda: None, None, graph, queue=False, api_name="clear")
43
 
44
  demo.launch()
 
5
  def generate_graph(input_text,api_key,graph):
6
  if graph == []:
7
  kg = KnowledgeGraph(api_key)
8
+ graph.append(kg)
9
  else:
10
  kg = graph[0]
11
  kg.learn(str(input_text))
 
14
  return img,graph
15
 
16
  def answer_question(question,api_key,graph):
17
+ if graph == []:
18
  kg = KnowledgeGraph(api_key)
19
+ graph.append(kg)
20
  else:
21
  kg = graph[0]
22
  return kg.chat_qa(question)
23
 
24
+ def clear_graph(api_key,graph):
25
+ graph = []
26
+ kg = KnowledgeGraph(api_key)
27
+ graph.append(kg)
28
+ return graph,Image.new('RGB', (256, 256))
29
+
30
  title = "GPT-4 Knowledge Graph Generator"
31
  description = "Enter text to generate a knowledge graph using GPT4KG:"
32
 
 
45
  qa_btn.click(fn=answer_question, inputs=[question,api_key,graph], outputs=[answer])
46
 
47
  clear_btn = gr.Button("Clear graph")
48
+ clear_btn.click(fn=clear_graph, inputs=[api_key,graph], outputs=[graph,output_image],api_name="clear")
49
 
50
  demo.launch()