Spaces:
Running
Running
nicpopovic
commited on
Commit
•
82a7d32
1
Parent(s):
918b70e
Update app.py
Browse files
app.py
CHANGED
@@ -373,7 +373,9 @@ def generate_text(input_text, messages=None):
|
|
373 |
list_of_spans = [{"name": tok.convert_tokens_to_string(new_text[2][x[0]:x[1]]).strip(), "type": new_tags[tags[x[1]-1]]} for x in filter_spans(spans)[0] if new_tags[tags[x[1]-1]] != "O"]
|
374 |
|
375 |
out_dict = {"text": output_text.replace("<|endoftext|>", "").replace("<|begin_of_text|>", "").strip(), "entites": list_of_spans}
|
376 |
-
|
|
|
|
|
377 |
html_out = output.replace("<|endoftext|>", "").replace("<|begin_of_text|>", "").strip().split("<|end_header_id|>\n\n")[-1].replace("**", "")
|
378 |
|
379 |
yield [messages[-1]] + [{"role": "assistant", "content": html_out}]
|
@@ -477,14 +479,22 @@ footer {
|
|
477 |
</style>"""
|
478 |
|
479 |
|
480 |
-
example_messages=[{'role': 'user', 'content': '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
|
482 |
with gr.Blocks(css=css, fill_width=True) as demo:
|
483 |
chatbot = gr.Chatbot(type="messages", value=example_messages)
|
484 |
msg = gr.Textbox(submit_btn=True)
|
485 |
msg.submit(lambda: None, None, chatbot).then(generate_text, msg, chatbot, queue="queue")
|
486 |
# Add an examples section for users to pick from predefined messages
|
487 |
-
examples = gr.Examples(examples=["
|
488 |
|
489 |
|
490 |
|
|
|
373 |
list_of_spans = [{"name": tok.convert_tokens_to_string(new_text[2][x[0]:x[1]]).strip(), "type": new_tags[tags[x[1]-1]]} for x in filter_spans(spans)[0] if new_tags[tags[x[1]-1]] != "O"]
|
374 |
|
375 |
out_dict = {"text": output_text.replace("<|endoftext|>", "").replace("<|begin_of_text|>", "").strip(), "entites": list_of_spans}
|
376 |
+
|
377 |
+
if output.endswith("<|end_header_id|>\n\n"):
|
378 |
+
continue
|
379 |
html_out = output.replace("<|endoftext|>", "").replace("<|begin_of_text|>", "").strip().split("<|end_header_id|>\n\n")[-1].replace("**", "")
|
380 |
|
381 |
yield [messages[-1]] + [{"role": "assistant", "content": html_out}]
|
|
|
479 |
</style>"""
|
480 |
|
481 |
|
482 |
+
example_messages=[{'role': 'user', 'content': 'What can you tell me about the Beatles?'}, {'role': 'assistant', 'content': """<span class='highlight spanhighlight' data-tooltip-text='ORG' style='background-color: #756bb188'>The Beatles<span class='small-text'>ORG</span></span> were a <span class='highlight spanhighlight' data-tooltip-text='NORP' style='background-color: #a1d99b88'> British<span class='small-text'>NORP</span></span> rock band formed in <span class='highlight spanhighlight' data-tooltip-text='GPE' style='background-color: #e6550d88'> Liverpool<span class='small-text'>GPE</span></span>, <span class='highlight spanhighlight' data-tooltip-text='GPE' style='background-color: #e6550d88'> England<span class='small-text'>GPE</span></span> in <span class='highlight spanhighlight' data-tooltip-text='DATE' style='background-color: #6baed688'>1960<span class='small-text'>DATE</span></span>. They're widely considered one of the most influential and successful bands in the history of popular music.
|
483 |
+
|
484 |
+
Some key facts:
|
485 |
+
|
486 |
+
- Formed by <span class='highlight spanhighlight' data-tooltip-text='PERSON' style='background-color: #bcbddc88'> John Lennon<span class='small-text'>PERSON</span></span> (guitar), <span class='highlight spanhighlight' data-tooltip-text='PERSON' style='background-color: #bcbddc88'> Paul McCartney<span class='small-text'>PERSON</span></span> (bass guitar, vocals), <span class='highlight spanhighlight' data-tooltip-text='PERSON' style='background-color: #bcbddc88'> George Harrison<span class='small-text'>PERSON</span></span> (lead guitar, vocals) and <span class='highlight spanhighlight' data-tooltip-text='PERSON' style='background-color: #bcbddc88'> Ringo Starr<span class='small-text'>PERSON</span></span> (drums)
|
487 |
+
- Released iconic albums like <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'> "Sgt. Pepper's Lonely Hearts Club Band<span class='small-text'>WORK_OF_ART</span></span>," " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>Revolver<span class='small-text'>WORK_OF_ART</span></span>" and " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>Abbey Road<span class='small-text'>WORK_OF_ART</span></span>"
|
488 |
+
- Known for hits like " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>I Want to Hold Your Hand<span class='small-text'>WORK_OF_ART</span></span>," " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>Yesterday<span class='small-text'>WORK_OF_ART</span></span>," " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>Hey Jude<span class='small-text'>WORK_OF_ART</span></span>," and " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>Let It Be<span class='small-text'>WORK_OF_ART</span></span>"
|
489 |
+
|
490 |
+
They broke numerous records throughout their career, including being the <span class='highlight spanhighlight' data-tooltip-text='ORDINAL' style='background-color: #c7e9c088'> first<span class='small-text'>ORDINAL</span></span> band to have <span class='highlight spanhighlight' data-tooltip-text='CARDINAL' style='background-color: #3182bd88'> five<span class='small-text'>CARDINAL</span></span> <span class='highlight spanhighlight' data-tooltip-text='CARDINAL' style='background-color: #3182bd88'> number-one<span class='small-text'>CARDINAL</span></span> singles on the <span class='highlight spanhighlight' data-tooltip-text='ORG' style='background-color: #756bb188'> Billboard<span class='small-text'>ORG</span></span> Hot 100 chart at once (" <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>In My Life<span class='small-text'>WORK_OF_ART</span></span>," <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'> "Can't Buy Me Love<span class='small-text'>WORK_OF_ART</span></span>," " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>A Hard Day's Night<span class='small-text'>WORK_OF_ART</span></span>," " <span class='highlight spanhighlight' data-tooltip-text='WORK_OF_ART' style='background-color: #bdbdbd88'>She Loves You<span class='small-text'>WORK_OF_ART</span></span>")"""}]
|
491 |
|
492 |
with gr.Blocks(css=css, fill_width=True) as demo:
|
493 |
chatbot = gr.Chatbot(type="messages", value=example_messages)
|
494 |
msg = gr.Textbox(submit_btn=True)
|
495 |
msg.submit(lambda: None, None, chatbot).then(generate_text, msg, chatbot, queue="queue")
|
496 |
# Add an examples section for users to pick from predefined messages
|
497 |
+
examples = gr.Examples(examples=["What can you tell me about the Beatles?", "Whats the GDP of Norway?", "List some fun things to do in Miami", "What do you know about the KIT in Karlsruhe?"], inputs=msg, run_on_click=True, fn=generate_text, outputs=chatbot, cache_examples=False)
|
498 |
|
499 |
|
500 |
|