sudhakar272 commited on
Commit
37be743
·
verified ·
1 Parent(s): 4683e75

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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
- # Replace with your Hugging Face model ID (username/model-name)
12
- model_id = "satyanayak/transformer-basic"
13
- checkpoint_path = hf_hub_download(repo_id=model_id, filename="trained_model.pt")
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="We are accounted poor citizens, the"),
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 a prompt to generate Shakespeare-style text continuation",
78
  examples=[
79
- ["O Romeo, Romeo, wherefore art thou", 100, 1],
80
- ["To be, or not to be, that is", 60, 2],
81
- ["Friends, Romans, countrymen, lend me", 50, 3],
82
- ["All the world's a stage, and all the", 100, 1],
83
- ["Now is the winter of our discontent", 100, 1],
84
- ["If music be the food of love,", 100, 1],
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