GPitzpon
Browse files- app.py +53 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, set_seed
|
3 |
+
import random
|
4 |
+
|
5 |
+
title = "מחולל טקסט עברי מבוסס ג׳פיטי2 פצפון"
|
6 |
+
article = "מודל השפה אומן על ידי <a href=\"https://linktr.ee/Norod78\">דורון אדלר</a>"
|
7 |
+
description = "<p>Using <a href=\"https://huggingface.co/Norod78/distilgpt2-base-pretrained-he\">Norod78/distilgpt2-base-pretrained-he</a> for inference<p>"
|
8 |
+
|
9 |
+
examples = [
|
10 |
+
['אם מתחשק לכם לפעמים'],
|
11 |
+
["הארי פוטר חייך חיוך נבוך"],
|
12 |
+
["שלום, קוראים לי"],
|
13 |
+
]
|
14 |
+
|
15 |
+
model_id = "Norod78/distilgpt2-base-pretrained-he"
|
16 |
+
text_generator = pipeline('text-generation', model=model_id, tokenizer=model_id)
|
17 |
+
max_length = 96
|
18 |
+
top_k = 50
|
19 |
+
top_p = 0.95
|
20 |
+
temperature = 0.9
|
21 |
+
max_seed = (2**32)-1
|
22 |
+
global_seed = random.randint(0, max_seed)
|
23 |
+
|
24 |
+
def text_generation(input_text = ''):
|
25 |
+
global global_seed
|
26 |
+
global_seed = global_seed + 1
|
27 |
+
if global_seed >= max_seed:
|
28 |
+
global_seed = 0
|
29 |
+
if input_text == None or len(input_text) == 0:
|
30 |
+
input_text = "\n"
|
31 |
+
set_seed(global_seed)
|
32 |
+
generated_text = text_generator(input_text,
|
33 |
+
max_length=max_length,
|
34 |
+
top_k=top_k,
|
35 |
+
top_p=top_p,
|
36 |
+
temperature=temperature,
|
37 |
+
do_sample=True,
|
38 |
+
repetition_penalty=2.0,
|
39 |
+
num_return_sequences=1)
|
40 |
+
parsed_text = generated_text[0]["generated_text"].replace("<|startoftext|>", "").replace("\r","").replace("\n\n", "\n").replace("\t", " ").replace("<|pad|>", " * ").replace("\"\"", "\"").strip()
|
41 |
+
print("parsed_text = \"" + parsed_text + "\" (seed = " + str(global_seed) + ")")
|
42 |
+
return parsed_text
|
43 |
+
gr.Interface(
|
44 |
+
text_generation,
|
45 |
+
inputs=gr.Textbox(lines=1, label="הזינו פה את מילות הפתיחה של הטקסט, בחרו את אחת מן הדוגמאות המוכנות או השאירו ריק. מה שבא לכם", elem_id="input_text"),
|
46 |
+
outputs=gr.Textbox(type="text", label="פה מופיע הטקסט שהמחולל יוצר", elem_id="output_text"),
|
47 |
+
css="#output_text{direction: rtl} #input_text{direction: rtl}",
|
48 |
+
title=title,
|
49 |
+
description=description,
|
50 |
+
article=article,
|
51 |
+
examples=examples,
|
52 |
+
allow_flagging='never',
|
53 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
tokenizers
|
5 |
+
|