tomrb commited on
Commit
96cf3b7
·
1 Parent(s): 342de3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  description = """
4
  When in legal doubt, you better call BLOOM! Ask BLOOM any legal question:
@@ -9,14 +10,33 @@ examples = [["Adventurer is approached by a mysterious stranger in the tavern fo
9
 
10
 
11
 
12
- def greet(name):
13
- return "Hello " + name + "!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  demo = gr.Interface(
16
- fn=greet,
17
- inputs=gr.Textbox(lines=2, placeholder="Write your question here..."),
18
- outputs="text",
19
- title=title,
20
- description=description
 
21
  )
 
22
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
  description = """
5
  When in legal doubt, you better call BLOOM! Ask BLOOM any legal question:
 
10
 
11
 
12
 
13
+ generator = pipeline('text-generation', model='tomrb/bettercallbloom-3b')
14
+
15
+ def preprocess(text):
16
+ #We add 'Question :' and 'Answer #1:' at the start and end of the prompt
17
+ return "Question: " + text + "Answer #1:"
18
+
19
+
20
+ def generate(text):
21
+
22
+ preprocessed_text = preprocess(text)
23
+ result = generator(preprocessed_text, max_length=128)
24
+ output = re.split(r'\nQuestion:|Answer #|Title:',result[0]['generated_text'])[2]
25
+
26
+ return output
27
+
28
+ examples = [
29
+ ["I started a company with a friend. What types of legal documents should we fill in to clarify the ownership of the company?"],
30
+ ["[CA] I got a parking ticket in Toronto. How can I contest it?"],
31
+ ]
32
 
33
  demo = gr.Interface(
34
+ fn=generate,
35
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text", placeholder = "Write your question here..."),
36
+ outputs=gr.outputs.Textbox(label="Generated Text"),
37
+ examples=examples,
38
+ description=description,
39
+ title=title
40
  )
41
+
42
  demo.launch()