Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize Hugging Face pipelines
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model(task):
|
| 7 |
+
return pipeline(task, model="t5-small", tokenizer="t5-small", framework="pt")
|
| 8 |
+
|
| 9 |
+
humanizer = load_model("text2text-generation")
|
| 10 |
+
rephraser = load_model("text2text-generation")
|
| 11 |
+
|
| 12 |
+
# Streamlit App
|
| 13 |
+
st.title("Humanizer & Rephraser App")
|
| 14 |
+
st.subheader("Powered by Hugging Face and Streamlit")
|
| 15 |
+
|
| 16 |
+
# User Input
|
| 17 |
+
input_text = st.text_area("Enter the text you want to process:", "")
|
| 18 |
+
|
| 19 |
+
# Options
|
| 20 |
+
task_option = st.radio(
|
| 21 |
+
"Choose an option:",
|
| 22 |
+
("Humanize Text", "Rephrase Text"),
|
| 23 |
+
index=0
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Optional Settings
|
| 27 |
+
formality = st.slider("Creativity level (lower is more formal):", 0, 100, 50)
|
| 28 |
+
tone = st.selectbox("Select tone:", ["Casual", "Professional", "Neutral"])
|
| 29 |
+
|
| 30 |
+
# Process Button
|
| 31 |
+
if st.button("Generate Output"):
|
| 32 |
+
if input_text.strip():
|
| 33 |
+
with st.spinner("Processing..."):
|
| 34 |
+
if task_option == "Humanize Text":
|
| 35 |
+
prompt = f"humanize: {input_text}"
|
| 36 |
+
result = humanizer(prompt, max_length=128, num_return_sequences=1, temperature=formality / 100)
|
| 37 |
+
else:
|
| 38 |
+
prompt = f"rephrase: {input_text}"
|
| 39 |
+
result = rephraser(prompt, max_length=128, num_return_sequences=1, temperature=formality / 100)
|
| 40 |
+
|
| 41 |
+
st.success("Done!")
|
| 42 |
+
st.write("**Output:**")
|
| 43 |
+
st.write(result[0]['generated_text'])
|
| 44 |
+
else:
|
| 45 |
+
st.error("Please enter some text to process.")
|
| 46 |
+
|
| 47 |
+
# Deployment Tip
|
| 48 |
+
st.info("To deploy, run the app using `streamlit run app.py` in your terminal.")
|