Spaces:
Running
on
Zero
Running
on
Zero
fixes
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import spaces
|
4 |
-
|
5 |
-
import io
|
6 |
|
7 |
|
8 |
models = {
|
@@ -20,9 +19,11 @@ def run_example(html_content, model_id="jinaai/reader-lm-0.5b"):
|
|
20 |
tokenizer = tokenizers[model_id]
|
21 |
messages = [{"role": "user", "content": html_content}]
|
22 |
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
|
23 |
-
inputs = tokenizer.encode(input_text, return_tensors="pt").to(
|
24 |
outputs = model.generate(inputs, max_new_tokens=1024, temperature=0, do_sample=False, repetition_penalty=1.08)
|
25 |
-
|
|
|
|
|
26 |
|
27 |
|
28 |
css = """
|
@@ -40,7 +41,7 @@ with gr.Blocks(css=css) as demo:
|
|
40 |
with gr.Tab(label="Main"):
|
41 |
with gr.Row():
|
42 |
with gr.Column():
|
43 |
-
model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="
|
44 |
html_content = gr.Textbox(label="HTML")
|
45 |
submit_btn = gr.Button(value="Submit")
|
46 |
with gr.Column():
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import spaces
|
4 |
+
import re
|
|
|
5 |
|
6 |
|
7 |
models = {
|
|
|
19 |
tokenizer = tokenizers[model_id]
|
20 |
messages = [{"role": "user", "content": html_content}]
|
21 |
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
|
22 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
|
23 |
outputs = model.generate(inputs, max_new_tokens=1024, temperature=0, do_sample=False, repetition_penalty=1.08)
|
24 |
+
pattern = r"<\|im_start\|>assistant(.*?)<\|im_end\|>"
|
25 |
+
assistant_response = re.findall(pattern, tokenizer.decode(outputs[0]), re.DOTALL)
|
26 |
+
return assistant_response[0]
|
27 |
|
28 |
|
29 |
css = """
|
|
|
41 |
with gr.Tab(label="Main"):
|
42 |
with gr.Row():
|
43 |
with gr.Column():
|
44 |
+
model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="jinaai/reader-lm-0.5b")
|
45 |
html_content = gr.Textbox(label="HTML")
|
46 |
submit_btn = gr.Button(value="Submit")
|
47 |
with gr.Column():
|