Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import rdflib
|
| 3 |
import json
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Função para carregar e extrair os nomes do arquivo JSON-LD
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
names = []
|
| 11 |
for item in data['@graph']:
|
|
@@ -14,8 +16,8 @@ def load_names_from_jsonld(jsonld_file):
|
|
| 14 |
|
| 15 |
return names
|
| 16 |
|
| 17 |
-
# Carregar nomes do arquivo JSON-LD
|
| 18 |
-
names =
|
| 19 |
|
| 20 |
def run_query_and_visualize(qtext, turtle_file):
|
| 21 |
# Carrega o arquivo Turtle
|
|
@@ -47,7 +49,6 @@ def run_query_and_visualize(qtext, turtle_file):
|
|
| 47 |
def update_query(selected_location):
|
| 48 |
return f"""
|
| 49 |
PREFIX schema: <http://schema.org/>
|
| 50 |
-
|
| 51 |
SELECT * WHERE {{
|
| 52 |
?s schema:name "{selected_location}" .
|
| 53 |
?s ?p ?o .
|
|
@@ -66,7 +67,7 @@ with gr.Blocks() as demo:
|
|
| 66 |
graph_output = gr.HTML()
|
| 67 |
|
| 68 |
def on_location_change(loc):
|
| 69 |
-
|
| 70 |
|
| 71 |
selected_location.change(fn=on_location_change, inputs=selected_location, outputs=query_input)
|
| 72 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import rdflib
|
| 3 |
import json
|
| 4 |
+
import requests
|
| 5 |
+
from pyvis.network import Network
|
| 6 |
|
| 7 |
+
# Função para carregar e extrair os nomes do arquivo JSON-LD a partir de um URL
|
| 8 |
+
def load_names_from_url(url):
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
data = response.json()
|
| 11 |
|
| 12 |
names = []
|
| 13 |
for item in data['@graph']:
|
|
|
|
| 16 |
|
| 17 |
return names
|
| 18 |
|
| 19 |
+
# Carregar nomes do arquivo JSON-LD a partir do URL
|
| 20 |
+
names = load_names_from_url('https://huggingface.co/spaces/histlearn/ShowGraph/raw/main/datafile.jsonld')
|
| 21 |
|
| 22 |
def run_query_and_visualize(qtext, turtle_file):
|
| 23 |
# Carrega o arquivo Turtle
|
|
|
|
| 49 |
def update_query(selected_location):
|
| 50 |
return f"""
|
| 51 |
PREFIX schema: <http://schema.org/>
|
|
|
|
| 52 |
SELECT * WHERE {{
|
| 53 |
?s schema:name "{selected_location}" .
|
| 54 |
?s ?p ?o .
|
|
|
|
| 67 |
graph_output = gr.HTML()
|
| 68 |
|
| 69 |
def on_location_change(loc):
|
| 70 |
+
return update_query(loc)
|
| 71 |
|
| 72 |
selected_location.change(fn=on_location_change, inputs=selected_location, outputs=query_input)
|
| 73 |
|