Spaces:
Paused
Paused
Commit
·
4d483b8
1
Parent(s):
0bdc91f
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import transformers
|
| 3 |
+
from transformers import pipeline, set_seed
|
| 4 |
+
import random
|
| 5 |
+
import time
|
| 6 |
+
import textblob
|
| 7 |
+
from textblob import TextBlob
|
| 8 |
+
|
| 9 |
+
@st.cache
|
| 10 |
+
def run_model(input_text):
|
| 11 |
+
set_seed(42)
|
| 12 |
+
model = pipeline("text-generation", model="bert-base-cased", tokenizer="bert-base-cased")
|
| 13 |
+
generated_text = model(input_text, max_length=1024, num_return_sequences=1).generated_text[0]
|
| 14 |
+
return generated_text
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
st.set_page_config(page_title="Paraphraser", page_icon=":guardsman:", layout="wide")
|
| 18 |
+
st.title("Paraphraser")
|
| 19 |
+
|
| 20 |
+
input_text = st.text_area("Input Text", "Type your text here")
|
| 21 |
+
options = st.selectbox("Paraphrase Options", ["Correct Grammar", "Remove Special Characters"])
|
| 22 |
+
|
| 23 |
+
if options == "Correct Grammar":
|
| 24 |
+
input_text = str(TextBlob(input_text).correct())
|
| 25 |
+
|
| 26 |
+
if options == "Remove Special Characters":
|
| 27 |
+
input_text = ''.join(e for e in input_text if e.isalnum() or e.isspace())
|
| 28 |
+
|
| 29 |
+
progress_bar = st.progress(0)
|
| 30 |
+
|
| 31 |
+
if st.button("Paraphrase"):
|
| 32 |
+
generated_text = run_model(input_text)
|
| 33 |
+
st.write("Generated Text:", generated_text)
|
| 34 |
+
st.write("Paraphrasing completed!")
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
main()
|