Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,19 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import random
|
| 4 |
import re
|
|
|
|
|
|
|
| 5 |
|
| 6 |
title = "WoW Quest Text Generator"
|
| 7 |
description = "Tap on the \"Submit\" button to generate a random quest text."
|
| 8 |
article = "<p>Fine tuned <a href=\"https://huggingface.co/EleutherAI/gpt-neo-125M\">EleutherAI/gpt-neo-125M</a> upon a formatted <a href=\"https://github.com/TrinityCore/TrinityCore\"> TrinityCore – TDB_full_world_927.22082_2022_08_21 Dataset</a></p><p>This generator is fan made and is not affiliated in any way with Blizzard and/or any other company</p>"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
model_id = "./model"
|
| 11 |
-
text_generator = pipeline("text-generation", model=model_id, tokenizer=model_id)
|
| 12 |
-
max_length =
|
| 13 |
top_k = 40
|
| 14 |
top_p = 0.92
|
| 15 |
temperature = 1.0
|
|
@@ -43,6 +48,7 @@ def parseSpecialCharacters(text, wow_class_item, wow_race_item, wow_silly_name_i
|
|
| 43 |
parsedText = text.replace("$a", "\n").replace("$B", "\n").replace("$b", "\n").replace("$c", wow_class_item).replace("$C", wow_class_item).replace("$r", wow_race_item).replace("$R", wow_race_item).replace("$n", wow_silly_name_item).replace("$N", wow_silly_name_item)
|
| 44 |
return parseGenderTokens(parsedText)
|
| 45 |
|
|
|
|
| 46 |
def text_generation(input_text = None):
|
| 47 |
if input_text == None or len(input_text) == 0:
|
| 48 |
input_text = "<|startoftext|>"
|
|
@@ -65,14 +71,17 @@ def text_generation(input_text = None):
|
|
| 65 |
parsed_text = parsed_text.replace("\\n", "\n")
|
| 66 |
return parsed_text
|
| 67 |
|
| 68 |
-
gr.Interface(
|
| 69 |
text_generation,
|
| 70 |
-
|
| 71 |
-
outputs=
|
| 72 |
title=title,
|
| 73 |
description=description,
|
| 74 |
article=article,
|
| 75 |
examples=suggested_text_list,
|
| 76 |
theme="default",
|
| 77 |
allow_flagging=False,
|
| 78 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import random
|
| 4 |
import re
|
| 5 |
+
import torch
|
| 6 |
+
import spaces
|
| 7 |
|
| 8 |
title = "WoW Quest Text Generator"
|
| 9 |
description = "Tap on the \"Submit\" button to generate a random quest text."
|
| 10 |
article = "<p>Fine tuned <a href=\"https://huggingface.co/EleutherAI/gpt-neo-125M\">EleutherAI/gpt-neo-125M</a> upon a formatted <a href=\"https://github.com/TrinityCore/TrinityCore\"> TrinityCore – TDB_full_world_927.22082_2022_08_21 Dataset</a></p><p>This generator is fan made and is not affiliated in any way with Blizzard and/or any other company</p>"
|
| 11 |
|
| 12 |
+
CUDA_AVAILABLE = torch.cuda.is_available()
|
| 13 |
+
device = torch.device("cuda" if CUDA_AVAILABLE else "cpu")
|
| 14 |
+
|
| 15 |
model_id = "./model"
|
| 16 |
+
text_generator = pipeline("text-generation", model=model_id, tokenizer=model_id, device=device)
|
| 17 |
+
max_length = 256
|
| 18 |
top_k = 40
|
| 19 |
top_p = 0.92
|
| 20 |
temperature = 1.0
|
|
|
|
| 48 |
parsedText = text.replace("$a", "\n").replace("$B", "\n").replace("$b", "\n").replace("$c", wow_class_item).replace("$C", wow_class_item).replace("$r", wow_race_item).replace("$R", wow_race_item).replace("$n", wow_silly_name_item).replace("$N", wow_silly_name_item)
|
| 49 |
return parseGenderTokens(parsedText)
|
| 50 |
|
| 51 |
+
@spaces.GPU
|
| 52 |
def text_generation(input_text = None):
|
| 53 |
if input_text == None or len(input_text) == 0:
|
| 54 |
input_text = "<|startoftext|>"
|
|
|
|
| 71 |
parsed_text = parsed_text.replace("\\n", "\n")
|
| 72 |
return parsed_text
|
| 73 |
|
| 74 |
+
demo = gr.Interface(
|
| 75 |
text_generation,
|
| 76 |
+
inputs=gr.Textbox(Textbox(lines=1, label="Enter strating text or leave blank"),
|
| 77 |
+
outputs=gr.Textbox(type="text", label="Generated quest text")],
|
| 78 |
title=title,
|
| 79 |
description=description,
|
| 80 |
article=article,
|
| 81 |
examples=suggested_text_list,
|
| 82 |
theme="default",
|
| 83 |
allow_flagging=False,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
demo.queue()
|
| 87 |
+
demo.launch()
|