elonmuskceo commited on
Commit
8431c4c
1 Parent(s): 997300a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -1,21 +1,41 @@
1
  import gradio as gr
 
 
 
2
  import sparknlp
3
 
4
  print("Sparknlp Version: " + sparknlp.version())
5
 
6
-
 
 
 
 
 
7
  spark = sparknlp.start()
8
 
 
 
 
 
 
 
 
 
 
9
  print(spark)
10
 
11
- def greet(name):
12
- return "Hello " + name + "!!"
 
13
 
14
  iface = gr.Interface(
15
- fn=greet,
16
  inputs="text",
17
- outputs="text",
 
18
  description=f"Spark object: {spark}",
 
19
  )
20
 
21
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from sparknlp.base import *
3
+ from sparknlp.annotator import *
4
+ from sparknlp.pretrained import PretrainedPipeline
5
  import sparknlp
6
 
7
  print("Sparknlp Version: " + sparknlp.version())
8
 
9
+ # Start SparkSession with Spark NLP
10
+ # start() functions has 4 parameters: gpu, spark23, spark24, and memory
11
+ # sparknlp.start(gpu=True) will start the session with GPU support
12
+ # sparknlp.start(spark23=True) is when you have Apache Spark 2.3.x installed
13
+ # sparknlp.start(spark24=True) is when you have Apache Spark 2.4.x installed
14
+ # sparknlp.start(memory="16G") to change the default driver memory in SparkSession
15
  spark = sparknlp.start()
16
 
17
+ # Download a pre-trained pipeline
18
+ pipeline = PretrainedPipeline('explain_document_dl', lang='en')
19
+
20
+ # Your testing dataset
21
+ placeholder = """
22
+ The Mona Lisa is a 16th century oil painting created by Leonardo.
23
+ It's held at the Louvre in Paris.
24
+ """
25
+
26
  print(spark)
27
 
28
+ def fn(text: str):
29
+ result = pipeline.annotate(text)
30
+ return result
31
 
32
  iface = gr.Interface(
33
+ fn=fn,
34
  inputs="text",
35
+ outputs="json",
36
+ title="Spark NLP explain_document_dl pipeline"
37
  description=f"Spark object: {spark}",
38
+ examples=[placeholder],
39
  )
40
 
41
  if __name__ == "__main__":