Instructions to use MCS12/llama-3-xml-presentation-generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MCS12/llama-3-xml-presentation-generator with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MCS12/llama-3-xml-presentation-generator", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload handler.py
Browse files- handler.py +22 -3
handler.py
CHANGED
|
@@ -13,8 +13,6 @@ from transformers import (
|
|
| 13 |
|
| 14 |
class EndpointHandler:
|
| 15 |
def __init__(self, path=""):
|
| 16 |
-
pass
|
| 17 |
-
|
| 18 |
peft_config = PeftConfig.from_pretrained(path)
|
| 19 |
|
| 20 |
# Load the base model with quantization
|
|
@@ -73,6 +71,7 @@ class EndpointHandler:
|
|
| 73 |
do_sample=True,
|
| 74 |
repetition_penalty=1.15,
|
| 75 |
)
|
|
|
|
| 76 |
available_tags = ["presentation", "slide", "ul", "ol", "li", "h1", "h2", "h3", "p"]
|
| 77 |
available_stylings = ["bold", "italic", "underline", "color", "align", "fontSize"]
|
| 78 |
prediction = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
@@ -83,6 +82,14 @@ class EndpointHandler:
|
|
| 83 |
if (prediction.startswith("<presentation>", i)):
|
| 84 |
start_indices.append(i)
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
start_index = start_indices[-1]
|
| 87 |
end_index = prediction.find("</presentation>") + 15
|
| 88 |
prediction = prediction[start_index:end_index]
|
|
@@ -154,7 +161,9 @@ def start_with_valid_tag(text, index):
|
|
| 154 |
# </ul>
|
| 155 |
# </slide>
|
| 156 |
# <slide id="2"[>
|
| 157 |
-
# <h2>Second Slide</h2>
|
|
|
|
|
|
|
| 158 |
# </slide>
|
| 159 |
# </presentation>"""
|
| 160 |
|
|
@@ -168,4 +177,14 @@ def start_with_valid_tag(text, index):
|
|
| 168 |
# sample_xml = sample_xml[:close_index - 1] + sample_xml[close_index:]
|
| 169 |
# offset += 1
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
# print(sample_xml)
|
|
|
|
| 13 |
|
| 14 |
class EndpointHandler:
|
| 15 |
def __init__(self, path=""):
|
|
|
|
|
|
|
| 16 |
peft_config = PeftConfig.from_pretrained(path)
|
| 17 |
|
| 18 |
# Load the base model with quantization
|
|
|
|
| 71 |
do_sample=True,
|
| 72 |
repetition_penalty=1.15,
|
| 73 |
)
|
| 74 |
+
|
| 75 |
available_tags = ["presentation", "slide", "ul", "ol", "li", "h1", "h2", "h3", "p"]
|
| 76 |
available_stylings = ["bold", "italic", "underline", "color", "align", "fontSize"]
|
| 77 |
prediction = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 82 |
if (prediction.startswith("<presentation>", i)):
|
| 83 |
start_indices.append(i)
|
| 84 |
|
| 85 |
+
if (prediction.startswith("true", i)):
|
| 86 |
+
if not ((ord(prediction[i - 1]) == 39 and ord(prediction[i+4]) == 39) or (ord(prediction[i-1]) == 34 and ord(prediction[i+4]) == 34)):
|
| 87 |
+
prediction = prediction[:i] + "\'" + prediction[i:i+4] + "\'" + prediction[i+4:]
|
| 88 |
+
|
| 89 |
+
if (prediction.startswith("false", i)):
|
| 90 |
+
if not ((ord(prediction[i - 1]) == 39 and ord(prediction[i+5]) == 39) or (ord(prediction[i-1]) == 34 and ord(prediction[i+5]) == 34)):
|
| 91 |
+
prediction = prediction[:i] + "\'" + prediction[i:i+5] + "\'" + prediction[i+5:]
|
| 92 |
+
|
| 93 |
start_index = start_indices[-1]
|
| 94 |
end_index = prediction.find("</presentation>") + 15
|
| 95 |
prediction = prediction[start_index:end_index]
|
|
|
|
| 161 |
# </ul>
|
| 162 |
# </slide>
|
| 163 |
# <slide id="2"[>
|
| 164 |
+
# <h2 bold=true>Second Slide</h2>
|
| 165 |
+
# <h1 italic=true>hi</h1>
|
| 166 |
+
# <h1 italic=false>hi</h1>
|
| 167 |
# </slide>
|
| 168 |
# </presentation>"""
|
| 169 |
|
|
|
|
| 177 |
# sample_xml = sample_xml[:close_index - 1] + sample_xml[close_index:]
|
| 178 |
# offset += 1
|
| 179 |
|
| 180 |
+
# for i in range(len(sample_xml)):
|
| 181 |
+
# if (sample_xml.startswith("true", i)):
|
| 182 |
+
# if not ((ord(sample_xml[i - 1]) == 39 and ord(sample_xml[i+4]) == 39) or (ord(sample_xml[i-1]) == 34 and ord(sample_xml[i+4]) == 34)):
|
| 183 |
+
# sample_xml = sample_xml[:i] + "\'" + sample_xml[i:i+4] + "\'" + sample_xml[i+4:]
|
| 184 |
+
# offset += 1
|
| 185 |
+
|
| 186 |
+
# if (sample_xml.startswith("false", i)):
|
| 187 |
+
# if not ((ord(sample_xml[i - 1]) == 39 and ord(sample_xml[i+5]) == 39) or (ord(sample_xml[i-1]) == 34 and ord(sample_xml[i+5]) == 34)):
|
| 188 |
+
# sample_xml = sample_xml[:i] + "\'" + sample_xml[i:i+5] + "\'" + sample_xml[i+5:]
|
| 189 |
+
|
| 190 |
# print(sample_xml)
|