Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
7661c65 8431c4c 7661c65 ffea8f6 8431c4c ffea8f6 8431c4c ffea8f6 997300a 8431c4c 997300a 8431c4c 997300a 8431c4c 318b509 997300a 8431c4c 997300a |
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 |
import gradio as gr
from sparknlp.base import *
from sparknlp.annotator import *
from sparknlp.pretrained import PretrainedPipeline
import sparknlp
print("Sparknlp Version: " + sparknlp.version())
# Start SparkSession with Spark NLP
# start() functions has 4 parameters: gpu, spark23, spark24, and memory
# sparknlp.start(gpu=True) will start the session with GPU support
# sparknlp.start(spark23=True) is when you have Apache Spark 2.3.x installed
# sparknlp.start(spark24=True) is when you have Apache Spark 2.4.x installed
# sparknlp.start(memory="16G") to change the default driver memory in SparkSession
spark = sparknlp.start()
# Download a pre-trained pipeline
pipeline = PretrainedPipeline('explain_document_dl', lang='en')
# Your testing dataset
placeholder = """
The Mona Lisa is a 16th century oil painting created by Leonardo.
It's held at the Louvre in Paris.
"""
print(spark)
def fn(text: str):
result = pipeline.annotate(text)
return result
iface = gr.Interface(
fn=fn,
inputs="text",
outputs="json",
title="Spark NLP explain_document_dl pipeline",
description=f"Spark object: {spark}",
examples=[placeholder],
)
if __name__ == "__main__":
iface.launch()
|