Spaces:
Paused
Paused
alakxender
commited on
Commit
·
0453eb7
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- .gitignore +1 -0
- README.md +12 -0
- app.py +115 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio_cached_examples
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Dhivehi Text Generator (GPT-2, Wiki)
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.6.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline, GPT2TokenizerFast
|
4 |
+
|
5 |
+
mode_id = "alakxender/dv-wiki-gpt2"
|
6 |
+
tokenizer = GPT2TokenizerFast.from_pretrained(mode_id, model_max_length=128)
|
7 |
+
|
8 |
+
generator = pipeline("text-generation", model=mode_id, tokenizer=tokenizer, pad_token_id=tokenizer.pad_token_id, eos_token_id=tokenizer.eos_token_id)
|
9 |
+
|
10 |
+
@spaces.GPU
|
11 |
+
def generate_text(prompt, max_length, temperature):
|
12 |
+
try:
|
13 |
+
generated = generator(
|
14 |
+
prompt,
|
15 |
+
max_length=max_length,
|
16 |
+
temperature=temperature,
|
17 |
+
do_sample=True,
|
18 |
+
repetition_penalty=1.4
|
19 |
+
)
|
20 |
+
return generated[0]['generated_text']
|
21 |
+
except Exception as e:
|
22 |
+
return f"Something went wrong, try again. Error: {str(e)}"
|
23 |
+
|
24 |
+
styles = """
|
25 |
+
.thaana textarea {
|
26 |
+
font-size: 18px !important;
|
27 |
+
font-family: 'MV_Faseyha', 'Faruma', 'A_Faruma' !important;
|
28 |
+
line-height: 1.8 !important;
|
29 |
+
}
|
30 |
+
.textbox2 textarea {
|
31 |
+
display: none;
|
32 |
+
}
|
33 |
+
"""
|
34 |
+
|
35 |
+
def create_interface(css=styles):
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("# Dhivehi Text Generator (GPT-2, Wiki)")
|
38 |
+
gr.Markdown(
|
39 |
+
"This is a GPT-2 model trained from Dhivehi text data from wikipedia"
|
40 |
+
"Enter some text and generate a new text, adjust the parameters to generate text."
|
41 |
+
)
|
42 |
+
gr.Markdown("""
|
43 |
+
**Parameters:**
|
44 |
+
|
45 |
+
- **Temperature**: Controls the creativity of the output.
|
46 |
+
- Lower values (0.2) = More focused and predictable text
|
47 |
+
- Higher values (0.8) = More diverse and creative text
|
48 |
+
|
49 |
+
- **Maximum Length**: Controls the length of generated text.
|
50 |
+
- Higher values generate longer, more detailed results
|
51 |
+
- Note: Longer texts take more time to generate
|
52 |
+
""")
|
53 |
+
|
54 |
+
with gr.Row():
|
55 |
+
input_temperature = gr.Slider(
|
56 |
+
minimum=0.1,
|
57 |
+
maximum=1.0,
|
58 |
+
value=0.7,
|
59 |
+
step=0.1,
|
60 |
+
label="Temperature",
|
61 |
+
)
|
62 |
+
input_max_length = gr.Slider(
|
63 |
+
minimum=10,
|
64 |
+
maximum=128,
|
65 |
+
value=60,
|
66 |
+
step=1,
|
67 |
+
label="Maximum Length",
|
68 |
+
)
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
with gr.Column(scale=1):
|
72 |
+
input_prompt = gr.Textbox(
|
73 |
+
label="Enter dhivehi text prompt",
|
74 |
+
placeholder="ދިވެހިން",
|
75 |
+
lines=5,
|
76 |
+
rtl=True,
|
77 |
+
elem_classes="thaana"
|
78 |
+
)
|
79 |
+
|
80 |
+
with gr.Column(scale=1):
|
81 |
+
output_text = gr.Textbox(
|
82 |
+
label="Generated Text",
|
83 |
+
lines=5,
|
84 |
+
interactive=True,
|
85 |
+
rtl=True,
|
86 |
+
elem_classes="thaana"
|
87 |
+
)
|
88 |
+
|
89 |
+
with gr.Row():
|
90 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
91 |
+
clear_btn = gr.ClearButton([input_prompt, output_text])
|
92 |
+
|
93 |
+
generate_btn.click(
|
94 |
+
fn=generate_text,
|
95 |
+
inputs=[input_prompt, input_max_length, input_temperature],
|
96 |
+
outputs=output_text
|
97 |
+
)
|
98 |
+
|
99 |
+
gr.Examples(
|
100 |
+
examples=[
|
101 |
+
["ދިވެހިރާއްޖެ"],
|
102 |
+
["އެމެރިކާ އިންތިޚާބު"],
|
103 |
+
["ސަލާމް"],
|
104 |
+
["ދުނިޔޭގެ ސިއްޙަތު ޖަމްޢިއްޔާ"],
|
105 |
+
["ޤަދީމީ ސަގާފަތް"],
|
106 |
+
["ޑިމޮކްރަސީ"]
|
107 |
+
],
|
108 |
+
inputs=input_prompt
|
109 |
+
)
|
110 |
+
|
111 |
+
return demo
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
demo = create_interface()
|
115 |
+
demo.queue().launch(show_api=False)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
tensorflow
|
3 |
+
accelerate
|
4 |
+
tf-keras
|