Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,18 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import nltk
|
| 3 |
import pandas as pd
|
| 4 |
from py_thesaurus import Thesaurus
|
| 5 |
import random
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
nltk.download('gutenberg')
|
| 11 |
-
from nltk.corpus import gutenberg
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
words = [word.lower() for word in text if word.isalpha()]
|
| 19 |
-
random_text = ' '.join(nltk.choice(words) for _ in range(10))
|
| 20 |
-
|
| 21 |
-
return random_text
|
| 22 |
|
| 23 |
# Function to replace a random word with its synonym
|
| 24 |
def replace_with_synonym(sentence):
|
|
@@ -60,8 +54,9 @@ st.write(scoreboard)
|
|
| 60 |
# Save scoreboard to output CSV file
|
| 61 |
scoreboard.to_csv('output.csv', index=False)
|
| 62 |
|
| 63 |
-
# Generate a random text
|
| 64 |
-
|
|
|
|
| 65 |
modified_text = replace_with_synonym(original_text)
|
| 66 |
|
| 67 |
# Display the modified text
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from py_thesaurus import Thesaurus
|
| 4 |
import random
|
| 5 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 6 |
|
| 7 |
+
# Load GPT-2 model and tokenizer
|
| 8 |
+
model = GPT2LMHeadModel.from_pretrained("gpt2")
|
| 9 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Function to generate random text using GPT-2
|
| 12 |
+
def generate_text(prompt):
|
| 13 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
| 14 |
+
outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
|
| 15 |
+
return tokenizer.decode(outputs[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Function to replace a random word with its synonym
|
| 18 |
def replace_with_synonym(sentence):
|
|
|
|
| 54 |
# Save scoreboard to output CSV file
|
| 55 |
scoreboard.to_csv('output.csv', index=False)
|
| 56 |
|
| 57 |
+
# Generate a random text using GPT-2
|
| 58 |
+
prompt = "Tell me a joke:"
|
| 59 |
+
original_text = generate_text(prompt)
|
| 60 |
modified_text = replace_with_synonym(original_text)
|
| 61 |
|
| 62 |
# Display the modified text
|