Spaces:
Build error
Build error
| import gradio as gr | |
| from transformers import pipeline | |
| title = "מחולל ציטוטים פיקטיביים של הארי פוטר" | |
| description = "<p align=\"right\">✨ נונסנס קסום</p>" | |
| article = "<p align=\"right\">מאת: <a href=\"https://linktr.ee/Norod78\">דורון אדלר</a></p>" | |
| model_id = "./model" | |
| text_generator = pipeline('text-generation', model=model_id, tokenizer=model_id) | |
| max_length = 128 | |
| top_k = 38 | |
| top_p = 0.92 | |
| temperature = 1.0 | |
| def text_generation(input_text = None): | |
| if input_text == None or len(input_text) == 0: | |
| input_text = ". " | |
| else: | |
| input_text =". " + 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[2:] | |
| gr.Interface( | |
| text_generation, | |
| inputs=None, | |
| outputs=gr.Textbox(lines=3, type="text", text_align = 'right', rtl = True, label="פה מופיע הטקסט שהמחולל יוצר", elem_id="output_text"), | |
| css="#output_text{direction: rtl} #input_text{direction: rtl}", | |
| title=title, | |
| description=description, | |
| article=article, | |
| theme="default", | |
| allow_flagging="never", | |
| ).launch() |