Update README.md
Browse files
README.md
CHANGED
|
@@ -17,18 +17,18 @@ import torch
|
|
| 17 |
import requests
|
| 18 |
from PIL import Image
|
| 19 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
|
|
| 20 |
|
| 21 |
def prepare(text):
|
| 22 |
text = text.replace('. ','.').replace(' .','.')
|
| 23 |
-
text = text.replace('< ','<').replace(' <','<')
|
| 24 |
-
text = text.replace('> ','>').replace(' >','>')
|
| 25 |
text = text.replace('( ','(').replace(' (','(')
|
| 26 |
text = text.replace(') ',')').replace(' )',')')
|
| 27 |
text = text.replace(': ',':').replace(' :',':')
|
| 28 |
text = text.replace('_ ','_').replace(' _','_')
|
| 29 |
-
text = text.replace(',(())','')
|
| 30 |
for i in range(10):
|
| 31 |
text = text.replace(')))','))').replace('(((','((')
|
|
|
|
| 32 |
return text
|
| 33 |
|
| 34 |
path_to_model = "blip-image2promt-stable-diffusion-v0.15"
|
|
@@ -46,7 +46,7 @@ out = model.generate(**inputs, max_new_tokens=100)
|
|
| 46 |
|
| 47 |
out_txt = processor.decode(out[0], skip_special_tokens=True)
|
| 48 |
|
| 49 |
-
print(prepare(out_txt))
|
| 50 |
```
|
| 51 |
|
| 52 |
|
|
|
|
| 17 |
import requests
|
| 18 |
from PIL import Image
|
| 19 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 20 |
+
import re
|
| 21 |
|
| 22 |
def prepare(text):
|
| 23 |
text = text.replace('. ','.').replace(' .','.')
|
|
|
|
|
|
|
| 24 |
text = text.replace('( ','(').replace(' (','(')
|
| 25 |
text = text.replace(') ',')').replace(' )',')')
|
| 26 |
text = text.replace(': ',':').replace(' :',':')
|
| 27 |
text = text.replace('_ ','_').replace(' _','_')
|
| 28 |
+
text = text.replace(',(())','').replace('(()),','')
|
| 29 |
for i in range(10):
|
| 30 |
text = text.replace(')))','))').replace('(((','((')
|
| 31 |
+
text = re.sub(r'<[^>]*>', '', text)
|
| 32 |
return text
|
| 33 |
|
| 34 |
path_to_model = "blip-image2promt-stable-diffusion-v0.15"
|
|
|
|
| 46 |
|
| 47 |
out_txt = processor.decode(out[0], skip_special_tokens=True)
|
| 48 |
|
| 49 |
+
print(prepare(out_txt)) # woman sitting on the beach at sunset, rear view,((happy)),((happy)),((dog)),((mixed)),(()),((
|
| 50 |
```
|
| 51 |
|
| 52 |
|