Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
from langdetect import detect
|
5 |
+
import language_tool_python
|
6 |
+
|
7 |
+
# Initialize models
|
8 |
+
summarizer = pipeline("summarization")
|
9 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
|
10 |
+
corrector = language_tool_python.LanguageTool('en-US')
|
11 |
+
|
12 |
+
st.set_page_config(page_title="CSS AI Assistant by Komal", layout="wide")
|
13 |
+
|
14 |
+
st.title("π CSS AI Assistant π΅π°")
|
15 |
+
st.write("Helping students with news summaries, precis, essays & more β for free!")
|
16 |
+
|
17 |
+
menu = st.sidebar.radio("Select Feature", [
|
18 |
+
"Daily News Summary",
|
19 |
+
"Precis Evaluation",
|
20 |
+
"Essay Feedback",
|
21 |
+
"Saved Notes"
|
22 |
+
])
|
23 |
+
|
24 |
+
# --- Daily News Summary ---
|
25 |
+
if menu == "Daily News Summary":
|
26 |
+
st.header("π° AI-Powered News Summarizer")
|
27 |
+
user_news = st.text_area("Paste or write today's news:", height=200)
|
28 |
+
lang = st.radio("Language", ["English", "Urdu"])
|
29 |
+
|
30 |
+
if st.button("Summarize") and user_news:
|
31 |
+
summary = summarizer(user_news, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
|
32 |
+
if lang == "Urdu":
|
33 |
+
translation = translator(summary)[0]['translation_text']
|
34 |
+
st.success("Summary in Urdu:")
|
35 |
+
st.write(translation)
|
36 |
+
else:
|
37 |
+
st.success("Summary in English:")
|
38 |
+
st.write(summary)
|
39 |
+
|
40 |
+
# --- Precis Evaluation ---
|
41 |
+
elif menu == "Precis Evaluation":
|
42 |
+
st.header("βοΈ Precis Evaluation Tool")
|
43 |
+
precis_input = st.text_area("Enter your precis for evaluation:", height=200)
|
44 |
+
if st.button("Evaluate Precis") and precis_input:
|
45 |
+
matches = corrector.check(precis_input)
|
46 |
+
corrected = language_tool_python.utils.correct(precis_input, matches)
|
47 |
+
st.success("β
Corrected Precis:")
|
48 |
+
st.write(corrected)
|
49 |
+
st.warning("β οΈ Mistakes Highlighted:")
|
50 |
+
for m in matches:
|
51 |
+
st.write(f"- {m.ruleId}: {m.message} (at position {m.offset})")
|
52 |
+
|
53 |
+
# --- Essay Feedback ---
|
54 |
+
elif menu == "Essay Feedback":
|
55 |
+
st.header("ποΈ Essay Evaluation Tool")
|
56 |
+
essay_input = st.text_area("Paste your essay here:", height=300)
|
57 |
+
if st.button("Evaluate Essay") and essay_input:
|
58 |
+
matches = corrector.check(essay_input)
|
59 |
+
corrected = language_tool_python.utils.correct(essay_input, matches)
|
60 |
+
st.success("β
Suggestions:")
|
61 |
+
st.write(corrected)
|
62 |
+
st.info(f"π {len(matches)} grammar/style issues found.")
|
63 |
+
for m in matches:
|
64 |
+
st.write(f"- {m.message} (Rule: {m.ruleId})")
|
65 |
+
|
66 |
+
# --- Saved Notes (Stub) ---
|
67 |
+
elif menu == "Saved Notes":
|
68 |
+
st.header("πΎ Saved Notes")
|
69 |
+
st.info("Note saving functionality coming soon!")
|
70 |
+
st.write("You will be able to store and download your summaries and corrected answers here.")
|