Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,14 +13,23 @@ st.markdown("""
|
|
| 13 |
background-color: #0e1117;
|
| 14 |
color: white;
|
| 15 |
}
|
| 16 |
-
.positive {background: linear-gradient(90deg, #3fc1c9, #4caf50); border-radius: 10px; padding: 1rem;}
|
| 17 |
-
.negative {background: linear-gradient(90deg, #f05454, #b33939); border-radius: 10px; padding: 1rem;}
|
| 18 |
-
.neutral {background: linear-gradient(90deg, #607d8b, #455a64); border-radius: 10px; padding: 1rem;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</style>
|
| 20 |
""", unsafe_allow_html=True)
|
| 21 |
|
| 22 |
st.title("🧠 AI Sentiment Essay Generator")
|
| 23 |
-
st.caption("Analyze
|
| 24 |
|
| 25 |
# ----------------------------------
|
| 26 |
# Model Initialization (cached)
|
|
@@ -76,7 +85,7 @@ if generate_btn and user_prompt.strip():
|
|
| 76 |
# Generate Essay
|
| 77 |
# ----------------------------------
|
| 78 |
with st.spinner("Generating essay with AI..."):
|
| 79 |
-
gen_prompt = f"Write a {sentiment_label.lower()} and expressive essay about: {user_prompt}"
|
| 80 |
|
| 81 |
input_ids = tokenizer(gen_prompt, return_tensors="pt").input_ids
|
| 82 |
output_ids = text_model.generate(
|
|
@@ -89,8 +98,16 @@ if generate_btn and user_prompt.strip():
|
|
| 89 |
)
|
| 90 |
generated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
st.markdown("### 📝 AI-Generated Essay")
|
| 93 |
-
|
|
|
|
| 94 |
|
| 95 |
st.markdown("---")
|
| 96 |
st.caption("✨ Powered by RoBERTa + Qwen | Streamlit Frontend")
|
|
|
|
| 13 |
background-color: #0e1117;
|
| 14 |
color: white;
|
| 15 |
}
|
| 16 |
+
.positive {background: linear-gradient(90deg, #3fc1c9, #4caf50); border-radius: 10px; padding: 1rem; margin-bottom:1rem;}
|
| 17 |
+
.negative {background: linear-gradient(90deg, #f05454, #b33939); border-radius: 10px; padding: 1rem; margin-bottom:1rem;}
|
| 18 |
+
.neutral {background: linear-gradient(90deg, #607d8b, #455a64); border-radius: 10px; padding: 1rem; margin-bottom:1rem;}
|
| 19 |
+
.essay-box {
|
| 20 |
+
background-color: #1e1e2e;
|
| 21 |
+
border: 1px solid #333;
|
| 22 |
+
border-radius: 10px;
|
| 23 |
+
padding: 1.5rem;
|
| 24 |
+
margin-top: 1rem;
|
| 25 |
+
color: #f1f1f1;
|
| 26 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.3);
|
| 27 |
+
}
|
| 28 |
</style>
|
| 29 |
""", unsafe_allow_html=True)
|
| 30 |
|
| 31 |
st.title("🧠 AI Sentiment Essay Generator")
|
| 32 |
+
st.caption("Analyze your topic’s sentiment and let AI write an expressive essay aligned with it 🎭")
|
| 33 |
|
| 34 |
# ----------------------------------
|
| 35 |
# Model Initialization (cached)
|
|
|
|
| 85 |
# Generate Essay
|
| 86 |
# ----------------------------------
|
| 87 |
with st.spinner("Generating essay with AI..."):
|
| 88 |
+
gen_prompt = f"Write a {sentiment_label.lower()} and expressive essay with a short title about: {user_prompt}"
|
| 89 |
|
| 90 |
input_ids = tokenizer(gen_prompt, return_tensors="pt").input_ids
|
| 91 |
output_ids = text_model.generate(
|
|
|
|
| 98 |
)
|
| 99 |
generated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 100 |
|
| 101 |
+
# Clean up output: remove initial instruction phrases
|
| 102 |
+
cleaned_text = generated_text.replace(gen_prompt, "").strip()
|
| 103 |
+
cleaned_text = cleaned_text.replace("Title:", "**Title:**").strip()
|
| 104 |
+
|
| 105 |
+
# ----------------------------------
|
| 106 |
+
# Display Essay in Styled Box
|
| 107 |
+
# ----------------------------------
|
| 108 |
st.markdown("### 📝 AI-Generated Essay")
|
| 109 |
+
|
| 110 |
+
st.markdown(f"<div class='essay-box'>{cleaned_text}</div>", unsafe_allow_html=True)
|
| 111 |
|
| 112 |
st.markdown("---")
|
| 113 |
st.caption("✨ Powered by RoBERTa + Qwen | Streamlit Frontend")
|