Upload app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,9 @@ from transformer import GPT, GPTConfig # Import your model class
|
|
8 |
# Load the model from Hugging Face Hub
|
9 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
10 |
def load_model_from_hf():
|
11 |
-
#
|
12 |
-
model_id = "
|
13 |
-
checkpoint_path = hf_hub_download(repo_id=model_id, filename="
|
14 |
|
15 |
checkpoint = torch.load(checkpoint_path, map_location=device)
|
16 |
config = checkpoint['config']
|
@@ -68,20 +68,20 @@ def generate_text(prompt, max_length=100, num_samples=1, temperature=0.8):
|
|
68 |
iface = gr.Interface(
|
69 |
fn=generate_text,
|
70 |
inputs=[
|
71 |
-
gr.Textbox(label="Prompt", value="
|
72 |
gr.Slider(minimum=10, maximum=200, value=100, step=1, label="Max Length"),
|
73 |
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of Samples"),
|
74 |
],
|
75 |
outputs=gr.Textbox(label="Generated Text"),
|
76 |
title="Shakespeare-style Text Generator",
|
77 |
-
description="Enter
|
78 |
examples=[
|
79 |
-
["
|
80 |
-
["
|
81 |
-
["
|
82 |
-
["
|
83 |
-
["
|
84 |
-
["
|
85 |
]
|
86 |
)
|
87 |
|
|
|
8 |
# Load the model from Hugging Face Hub
|
9 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
10 |
def load_model_from_hf():
|
11 |
+
# Hugging Face model ID (username/model-name)
|
12 |
+
model_id = "sudhakar272/shakespheretextgenerator"
|
13 |
+
checkpoint_path = hf_hub_download(repo_id=model_id, filename="transformer_model.pt")
|
14 |
|
15 |
checkpoint = torch.load(checkpoint_path, map_location=device)
|
16 |
config = checkpoint['config']
|
|
|
68 |
iface = gr.Interface(
|
69 |
fn=generate_text,
|
70 |
inputs=[
|
71 |
+
gr.Textbox(label="Prompt", value="Good night, good night! Parting is such sweet sorrow"),
|
72 |
gr.Slider(minimum=10, maximum=200, value=100, step=1, label="Max Length"),
|
73 |
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of Samples"),
|
74 |
],
|
75 |
outputs=gr.Textbox(label="Generated Text"),
|
76 |
title="Shakespeare-style Text Generator",
|
77 |
+
description="Enter text for Shakespear way of text continuation",
|
78 |
examples=[
|
79 |
+
["To be, or not to be: that is the question.", 100, 1],
|
80 |
+
["Love all, trust a few, do wrong to none.", 60, 2],
|
81 |
+
["It's not enough to speak, but to speak true", 50, 3],
|
82 |
+
["There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy.", 100, 1],
|
83 |
+
["If you can look into the seeds of time, and say which grain will grow and which will not, speak then to me", 100, 1],
|
84 |
+
["Love sought is good, but given unsought is better.", 100, 1],
|
85 |
]
|
86 |
)
|
87 |
|