Spaces:
Sleeping
Sleeping
naman4jain
commited on
Commit
•
2723dd7
1
Parent(s):
d0b87c9
Delete app.py
Browse files
app.py
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
-
|
4 |
-
# Load the GPT-2 model and tokenizer
|
5 |
-
model_name = "gpt2"
|
6 |
-
model = GPT2LMHeadModel.from_pretrained(model_name)
|
7 |
-
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# Define the sentence completion function
|
10 |
-
def complete_sentence(sentence):
|
11 |
-
input_ids = tokenizer.encode(sentence, return_tensors="pt")
|
12 |
-
output = model.generate(input_ids, max_length=50, num_return_sequences=1)
|
13 |
-
completed_sentence = tokenizer.decode(output[0], skip_special_tokens=True)
|
14 |
-
return completed_sentence
|
15 |
-
|
16 |
-
# Create the Gradio interface
|
17 |
-
iface = gr.Interface(
|
18 |
-
fn=complete_sentence,
|
19 |
-
inputs="text",
|
20 |
-
outputs="text",
|
21 |
-
title="Sentence Completion",
|
22 |
-
description="Enter a sentence to complete",
|
23 |
-
example="I love to"
|
24 |
-
)
|
25 |
-
|
26 |
-
# Launch the Gradio interface
|
27 |
-
if __name__ == "__main__":
|
28 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|