histlearn commited on
Commit
d1cb3da
·
verified ·
1 Parent(s): 547cf18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -25,10 +25,10 @@ names = load_names_from_url('https://huggingface.co/spaces/histlearn/ShowGraph/r
25
 
26
  print("Loaded names:", names) # Adicionando impressão para depuração
27
 
28
- def run_query_and_visualize(qtext, turtle_file):
29
- # Carrega o arquivo Turtle
30
  g = rdflib.Graph()
31
- g.parse(turtle_file, format="turtle")
32
 
33
  # Executa a consulta SPARQL
34
  qres = g.query(qtext)
@@ -70,7 +70,6 @@ with gr.Blocks() as demo:
70
  query_input = gr.Textbox(label="Consulta SPARQL", value=update_query(names[0]), lines=10)
71
  else:
72
  query_input = gr.Textbox(label="Consulta SPARQL", value="", lines=10)
73
- turtle_file_input = gr.File(label="Arquivo Turtle")
74
  run_button = gr.Button("Executar Consulta")
75
 
76
  graph_output = gr.HTML()
@@ -80,9 +79,9 @@ with gr.Blocks() as demo:
80
 
81
  selected_location.change(fn=on_location_change, inputs=selected_location, outputs=query_input)
82
 
83
- def on_run_button_click(query, turtle_file):
84
- return run_query_and_visualize(query, turtle_file.name)
85
 
86
- run_button.click(fn=on_run_button_click, inputs=[query_input, turtle_file_input], outputs=graph_output)
87
 
88
  demo.launch()
 
25
 
26
  print("Loaded names:", names) # Adicionando impressão para depuração
27
 
28
+ def run_query_and_visualize(qtext, jsonld_file):
29
+ # Carrega o arquivo JSON-LD
30
  g = rdflib.Graph()
31
+ g.parse(jsonld_file, format="json-ld")
32
 
33
  # Executa a consulta SPARQL
34
  qres = g.query(qtext)
 
70
  query_input = gr.Textbox(label="Consulta SPARQL", value=update_query(names[0]), lines=10)
71
  else:
72
  query_input = gr.Textbox(label="Consulta SPARQL", value="", lines=10)
 
73
  run_button = gr.Button("Executar Consulta")
74
 
75
  graph_output = gr.HTML()
 
79
 
80
  selected_location.change(fn=on_location_change, inputs=selected_location, outputs=query_input)
81
 
82
+ def on_run_button_click(query):
83
+ return run_query_and_visualize(query, 'https://huggingface.co/spaces/histlearn/ShowGraph/raw/main/datafile.jsonld')
84
 
85
+ run_button.click(fn=on_run_button_click, inputs=[query_input], outputs=graph_output)
86
 
87
  demo.launch()