mstftmk commited on
Commit
91d390a
·
1 Parent(s): 2b76124

Add all files

Browse files
Files changed (3) hide show
  1. README.md +50 -13
  2. app.py +29 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,50 @@
1
- ---
2
- title: Shakespeare GPT
3
- emoji: 👀
4
- colorFrom: pink
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.10.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Shakespeare-GPT Space
3
+
4
+ This space is a demonstration of a fine-tuned GPT-2 model trained on Shakespearean text, offering users the ability to generate text inspired by the Bard's style.
5
+
6
+ ## Features
7
+
8
+ - **Generate Text**: Input a prompt and let the model generate Shakespearean-style text.
9
+ - **Customizable Settings**: Adjust parameters like maximum length, temperature, and sampling method (e.g., top-p, top-k) for fine-tuned control over the output.
10
+ - **Gradio Interface**: User-friendly interface powered by Gradio for seamless interaction.
11
+
12
+ ## How to Use
13
+
14
+ 1. Enter a prompt in the input box.
15
+ 2. Adjust settings (optional) for generation control.
16
+ 3. Click the "Generate" button and wait for your text to appear.
17
+
18
+ ## Example Prompts
19
+
20
+ - "Oh noble knight, what hast thou seen?"
21
+ - "To love or not to love, that is the query."
22
+ - "The moon shines brightly upon the silent woods."
23
+
24
+ ## Technologies
25
+
26
+ - **Model**: GPT-2 fine-tuned on Shakespearean text.
27
+ - **Framework**: Gradio for the web interface.
28
+ - **Platform**: Hosted on Hugging Face Spaces.
29
+
30
+ ## Requirements
31
+
32
+ This space uses the following dependencies (also listed in `requirements.txt`):
33
+
34
+ ```
35
+ gradio
36
+ transformers
37
+ torch
38
+ ```
39
+
40
+ ## About the Model
41
+
42
+ The model was fine-tuned using the tinyShakespeare dataset. Its outputs are influenced by the training data, generating text that resembles Shakespearean prose and verse.
43
+
44
+ ## Acknowledgments
45
+
46
+ Special thanks to Hugging Face and Gradio for providing the tools to make this project possible.
47
+
48
+ ## License
49
+
50
+ This project is under the apache-2.0 license.
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "mstftmk/shakespeare-gpt2" # Replace with your model's repo
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ # Define the generation function
10
+ def generate_text(input_text, max_length, temperature):
11
+ inputs = tokenizer.encode(input_text, return_tensors="pt")
12
+ outputs = model.generate(inputs, max_length=max_length, temperature=temperature)
13
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+
15
+ # Create the Gradio interface
16
+ interface = gr.Interface(
17
+ fn=generate_text,
18
+ inputs=[
19
+ gr.Textbox(lines=2, placeholder="Enter your prompt..."),
20
+ gr.Slider(50, 300, value=100, label="Max Length"),
21
+ gr.Slider(0.1, 1.0, value=0.7, label="Temperature"),
22
+ ],
23
+ outputs=gr.Textbox(),
24
+ title="Shakespeare GPT-2",
25
+ description="Generate text inspired by Shakespeare.",
26
+ )
27
+
28
+ # Launch the Gradio app
29
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio