Spaces:
Sleeping
Sleeping
File size: 1,151 Bytes
fd9b3c0 bb76ad8 fd9b3c0 bb76ad8 fd9b3c0 bb76ad8 fd9b3c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
from huggingface_hub import InferenceClient
import rdflib
import gradio as gr
import rdflib
# Load the Turtle file and initialize the graph
g = rdflib.Graph()
g.parse('huggingface.ttl')
# Define the function to execute the SPARQL query
def run_sparql(query):
try:
qres = g.query(query)
results = []
for row in qres:
# Concatenate each row's results into a readable string
result = " | ".join(str(cell) for cell in row)
results.append(result)
return "\n".join(results) if results else "No results found."
except Exception as e:
return f"Error: {e}"
# Gradio interface
query_input = gr.Textbox(label="SPARQL Query", lines=5, placeholder="Enter your SPARQL query here")
output_text = gr.Textbox(label="Query Results", lines=10)
# Launch the app
demo = gr.Interface(
fn=run_sparql,
inputs=query_input,
outputs=output_text,
title="SPARQL Query Interface",
description="Enter a SPARQL query to retrieve data from the Turtle file.",
)
if __name__ == "__main__":
demo.launch()
if __name__ == "__main__":
demo.launch()
|