import gradio as gr | |
from transformers import pipeline | |
title = "מחולל קטעים מהרצאות טד" | |
description = "" | |
article = "<p>Fine tuned <a href=\"https://huggingface.co/Norod78/hebrew-gpt_neo-small\">Norod78/hebrew-gpt_neo-small</a> upon a formatted <a href=\"https://www.kaggle.com/datasets/miguelcorraljr/ted-ultimate-dataset\"> TED – Ultimate Dataset</a> (Hebrew)</p>" | |
model_id = "./model" | |
text_generator = pipeline('text-generation', model=model_id, tokenizer=model_id) | |
max_length = 128 | |
top_k = 40 | |
top_p = 0.92 | |
temperature = 1.0 | |
def text_generation(input_text = None): | |
if input_text == None or len(input_text) == 0: | |
input_text = "\t\"" | |
else: | |
if input_text.startswith("<|startoftext|>") == False: | |
input_text ="<|startoftext|>" + input_text | |
generated_text = text_generator(input_text, | |
max_length=max_length, | |
top_k=top_k, | |
top_p=top_p, | |
temperature=temperature, | |
do_sample=True, | |
repetition_penalty=2.0, | |
num_return_sequences=1) | |
parsed_text = generated_text[0]["generated_text"].replace("<|startoftext|>", "").replace("\r","").replace("\n\n", "\n").replace("\t", " ").replace("<|pad|>", " * ").replace("\"\"", "\"") | |
return parsed_text | |
gr.Interface( | |
text_generation, | |
inputs=gr.Textbox(lines=1, label="הזינו פה ציטוט פתיחה, או השאירו ריק. מה שבא לכם", elem_id="input_text"), | |
outputs=gr.Textbox(type="auto", label="פה מופיע הטקסט שהמחולל יוצר", elem_id="output_text"), | |
css="#output_text{direction: rtl} #input_text{direction: rtl}", | |
title=title, | |
description=description, | |
article=article, | |
theme="default", | |
allow_flagging=False, | |
).launch() |