Spaces:
No application file
No application file
Upload 10 files
Browse files- .idea/gpt-2.iml +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/workspace.xml +4 -0
- README.md +6 -12
- gpt.py +9 -0
- requirements.txt +2 -0
- run-gradio.py +24 -0
- screenshots/interface.png +0 -0
.idea/gpt-2.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="JavaScriptSettings">
|
4 |
+
<option name="languageLevel" value="ES6" />
|
5 |
+
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (GradioHub)" project-jdk-type="Python SDK" />
|
7 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/gpt-2.iml" filepath="$PROJECT_DIR$/.idea/gpt-2.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/workspace.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectId" id="1dgdlLVrrVfgwRsipZaHeoQG6FQ" />
|
4 |
+
</project>
|
README.md
CHANGED
@@ -1,13 +1,7 @@
|
|
1 |
-
|
2 |
-
title: Gpt2 Sharjeel
|
3 |
-
emoji: 🐠
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: yellow
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.8.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
# GPT-2 on Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+

|
4 |
+
|
5 |
+
- Loads `gpt-2`, but can load `gpt2-medium`, `gpt2-large` or `gpt2-xl`.
|
6 |
+
- `max_length` set to 100 (The max length of the sequence to be generated.)
|
7 |
+
- running `".".join(output.split(".")[:-1]) + "."` so that `max_length` doesn't stop an output abruptly.
|
gpt.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
|
2 |
+
import tensorflow
|
3 |
+
|
4 |
+
|
5 |
+
def get_model(name="gpt2"):
|
6 |
+
tokenizer = GPT2Tokenizer.from_pretrained(name)
|
7 |
+
model = TFGPT2LMHeadModel.from_pretrained(name,
|
8 |
+
pad_token_id=tokenizer.eos_token_id)
|
9 |
+
return model, tokenizer
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
tensorflow==2.1
|
2 |
+
transformers
|
run-gradio.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
from gpt import get_model
|
3 |
+
|
4 |
+
|
5 |
+
model, tokenizer = get_model()
|
6 |
+
|
7 |
+
def predict(inp):
|
8 |
+
input_ids = tokenizer.encode(inp, return_tensors='tf')
|
9 |
+
beam_output = model.generate(input_ids, max_length=100, num_beams=5,
|
10 |
+
no_repeat_ngram_size=2, early_stopping=True)
|
11 |
+
output = tokenizer.decode(beam_output[0], skip_special_tokens=True,
|
12 |
+
clean_up_tokenization_spaces=True)
|
13 |
+
return ".".join(output.split(".")[:-1]) + "."
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
INPUTS = gradio.inputs.Textbox()
|
18 |
+
OUTPUTS = gradio.outputs.Textbox()
|
19 |
+
INTERFACE = gradio.Interface(fn=predict, inputs=INPUTS, outputs=OUTPUTS, title="GPT-2",
|
20 |
+
description="GPT-2 is a large transformer-based language model with 1.5 billion parameters, trained on a dataset[1] of 8 million web pages. GPT-2 is trained with a simple objective: predict the next word, given all of the previous words within some text.",
|
21 |
+
thumbnail="https://github.com/gradio-app/gpt-2/raw/master/screenshots/interface.png?raw=true",
|
22 |
+
capture_session=False)
|
23 |
+
|
24 |
+
INTERFACE.launch(inbrowser=True)
|
screenshots/interface.png
ADDED
![]() |