Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
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=
|
28 |
-
|
29 |
-
|
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 = [
|