Spaces:
Sleeping
Sleeping
JakeTurner616
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,3 @@
|
|
1 |
-
from transformers import GPT2LMHeadModel, GPT2TokenizerFast, pipeline
|
2 |
import gradio as gr
|
3 |
-
import os
|
4 |
|
5 |
-
|
6 |
-
model_dir = "JakeTurner616/Adonalsium-gpt2"
|
7 |
-
|
8 |
-
# Manually specify the model's configuration and weights files
|
9 |
-
model = GPT2LMHeadModel.from_pretrained(model_dir, torch_dtype='auto', low_cpu_mem_usage=True)
|
10 |
-
tokenizer = GPT2TokenizerFast.from_pretrained(model_dir, use_fast=True)
|
11 |
-
|
12 |
-
# Ensure the tokenizer uses the correct pad token
|
13 |
-
tokenizer.pad_token = tokenizer.eos_token
|
14 |
-
|
15 |
-
# Create the text generation pipeline
|
16 |
-
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
17 |
-
|
18 |
-
def generate_text(prompt):
|
19 |
-
# Generate text
|
20 |
-
generated_texts = generator(prompt, max_length=150, temperature=0.7,
|
21 |
-
top_p=0.85, repetition_penalty=1.3,
|
22 |
-
num_return_sequences=1, no_repeat_ngram_size=2,
|
23 |
-
early_stopping=True)
|
24 |
-
return generated_texts[0]['generated_text']
|
25 |
-
|
26 |
-
# Create the Gradio interface
|
27 |
-
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text",
|
28 |
-
title="Cosmere Text Generator",
|
29 |
-
description="Generate text based on the Cosmere series by Brandon Sanderson.")
|
30 |
-
# Launch the interface
|
31 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
gr.load("models/JakeTurner616/Adonalsium-gpt2").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|