tomrb commited on
Commit
16e25b2
1 Parent(s): 7340b08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  from transformers import BloomTokenizerFast, BloomForCausalLM
4
- import re
5
 
6
  description = """
7
  When in legal doubt, you better call BLOOM! Ask BLOOM any legal question:
@@ -10,10 +9,12 @@ When in legal doubt, you better call BLOOM! Ask BLOOM any legal question:
10
  title = "Better Call Bloom!"
11
  examples = [["Adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
12
 
13
- tokenizer = BloomTokenizerFast.from_pretrained("tomrb/bettercallbloom-3b")
14
- model_8bit = BloomForCausalLM.from_pretrained("tomrb/bettercallbloom-3b",device_map="auto",load_in_8bit=True)
15
 
16
- generator = pipeline('text-generation', model=model_8bit, tokenizer=tokenizer)
 
 
 
 
17
 
18
 
19
  def preprocess(text):
@@ -24,9 +25,9 @@ def preprocess(text):
24
  def generate(text):
25
 
26
  preprocessed_text = preprocess(text)
27
- result = generator(preprocessed_text, max_length=256)
28
- #output = re.split(r'\nQuestion:|Answer #|Title:',result[0]['generated_text'])[2]
29
- output = result[0]['generated_text']
30
  return output
31
 
32
  examples = [
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  from transformers import BloomTokenizerFast, BloomForCausalLM
 
4
 
5
  description = """
6
  When in legal doubt, you better call BLOOM! Ask BLOOM any legal question:
 
9
  title = "Better Call Bloom!"
10
  examples = [["Adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
11
 
 
 
12
 
13
+
14
+ tokenizer = BloomTokenizerFast.from_pretrained("tomrb/bettercallbloom-3b-8bit")
15
+ model = BloomForCausalLM.from_pretrained("tomrb/bettercallbloom-3b-8bit")
16
+
17
+ generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
18
 
19
 
20
  def preprocess(text):
 
25
  def generate(text):
26
 
27
  preprocessed_text = preprocess(text)
28
+ result = generator(preprocessed_text, max_length=128)
29
+ output = re.split(r'\nQuestion:|Answer #|Title:',result[0]['generated_text'])[2]
30
+
31
  return output
32
 
33
  examples = [