Spaces:
Runtime error
Runtime error
Commit
·
99fbd97
1
Parent(s):
7b10293
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import subprocess
|
2 |
-
subprocess.run(["pip", "install",
|
3 |
import re
|
4 |
import gradio as gr
|
5 |
import torch
|
@@ -13,13 +13,15 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
13 |
# Define a function for generating text based on a prompt using the fine-tuned GPT-2 model and the tokenizer
|
14 |
def generate_text(prompt, length=100, theme=None, **kwargs):
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
# Load the model from the Hugging Face space
|
19 |
-
model = GPT2LMHeadModel.from_pretrained(
|
20 |
|
21 |
# Load the tokenizer from the Hugging Face space
|
22 |
-
tokenizer = GPT2Tokenizer.from_pretrained(
|
23 |
|
24 |
# If a theme is specified, add it to the prompt as a prefix for a special token
|
25 |
if theme:
|
@@ -65,7 +67,7 @@ def generate_text(prompt, length=100, theme=None, **kwargs):
|
|
65 |
iface = gr.Interface(
|
66 |
fn=generate_text,
|
67 |
inputs=[
|
68 |
-
|
69 |
gr.inputs.Slider(minimum=10, maximum=100, default=50, label='Length of text'),
|
70 |
gr.inputs.Textbox(default='Food', label='Theme')
|
71 |
],
|
|
|
1 |
import subprocess
|
2 |
+
subprocess.run(["pip", "install","gradio","torch","transformers"])
|
3 |
import re
|
4 |
import gradio as gr
|
5 |
import torch
|
|
|
13 |
# Define a function for generating text based on a prompt using the fine-tuned GPT-2 model and the tokenizer
|
14 |
def generate_text(prompt, length=100, theme=None, **kwargs):
|
15 |
|
16 |
+
model_url = "https://huggingface.co/spaces/sailormars18/Yelp-reviews-usingGPT2/blob/main/pytorch_model.bin"
|
17 |
+
config_url = "https://huggingface.co/spaces/sailormars18/Yelp-reviews-usingGPT2/blob/main/config.json"
|
18 |
+
generation_config_url = "https://huggingface.co/spaces/sailormars18/Yelp-reviews-usingGPT2/blob/main/generation_config.json"
|
19 |
|
20 |
# Load the model from the Hugging Face space
|
21 |
+
model = transformers.GPT2LMHeadModel.from_pretrained(model_url, config=config_url).to(device)
|
22 |
|
23 |
# Load the tokenizer from the Hugging Face space
|
24 |
+
tokenizer = transformers.GPT2Tokenizer.from_pretrained('gpt2')
|
25 |
|
26 |
# If a theme is specified, add it to the prompt as a prefix for a special token
|
27 |
if theme:
|
|
|
67 |
iface = gr.Interface(
|
68 |
fn=generate_text,
|
69 |
inputs=[
|
70 |
+
"text",
|
71 |
gr.inputs.Slider(minimum=10, maximum=100, default=50, label='Length of text'),
|
72 |
gr.inputs.Textbox(default='Food', label='Theme')
|
73 |
],
|