Spaces:
Running
on
Zero
Running
on
Zero
initial commit
Browse files- app.py +48 -4
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,7 +1,51 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import spaces
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
|
|
|
|
7 |
|
8 |
+
models = {
|
9 |
+
"jinaai/reader-lm-0.5b": AutoModelForCausalLM.from_pretrained("jinaai/reader-lm-0.5b", trust_remote_code=True).to("cuda").eval(),
|
10 |
+
}
|
11 |
+
|
12 |
+
tokenizers = {
|
13 |
+
"jinaai/reader-lm-0.5b": AutoTokenizer.from_pretrained("jinaai/reader-lm-0.5b", trust_remote_code=True),
|
14 |
+
}
|
15 |
+
|
16 |
+
|
17 |
+
@spaces.GPU
|
18 |
+
def run_example(html_content, model_id="jinaai/reader-lm-0.5b"):
|
19 |
+
model = models[model_id]
|
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(device)
|
24 |
+
outputs = model.generate(inputs, max_new_tokens=1024, temperature=0, do_sample=False, repetition_penalty=1.08)
|
25 |
+
return tokenizer.decode(outputs[0])
|
26 |
+
|
27 |
+
|
28 |
+
css = """
|
29 |
+
#output {
|
30 |
+
height: 500px;
|
31 |
+
overflow: auto;
|
32 |
+
border: 1px solid #ccc;
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
with gr.Blocks(css=css) as demo:
|
37 |
+
gr.Markdown("""
|
38 |
+
# HTML-to-Markdown
|
39 |
+
""")
|
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="maxiw/Florence-2-ScreenQA-base")
|
44 |
+
html_content = gr.Textbox(label="HTML")
|
45 |
+
submit_btn = gr.Button(value="Submit")
|
46 |
+
with gr.Column():
|
47 |
+
output_text = gr.Textbox(label="Markdown")
|
48 |
+
|
49 |
+
submit_btn.click(run_example, [html_content, model_selector], [output_text])
|
50 |
+
|
51 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers<=4.43.4
|