komalphulpoto commited on
Commit
939cd60
Β·
verified Β·
1 Parent(s): 8a35d1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -5
app.py CHANGED
@@ -1,17 +1,22 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- from langdetect import detect
 
 
4
 
5
  # Initialize models
6
  summarizer = pipeline("summarization")
7
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
 
8
  grammar_corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
9
 
 
10
  st.set_page_config(page_title="CSS AI Assistant by Komal", layout="wide")
11
 
12
  st.title("πŸ“š CSS AI Assistant πŸ‡΅πŸ‡°")
13
  st.write("Helping students with news summaries, precis, essays & more β€” for free!")
14
 
 
15
  menu = st.sidebar.radio("Select Feature", [
16
  "Daily News Summary",
17
  "Precis Evaluation",
@@ -19,6 +24,23 @@ menu = st.sidebar.radio("Select Feature", [
19
  "Saved Notes"
20
  ])
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  # --- Daily News Summary ---
23
  if menu == "Daily News Summary":
24
  st.header("πŸ“° AI-Powered News Summarizer")
@@ -28,16 +50,42 @@ if menu == "Daily News Summary":
28
  if st.button("Summarize") and user_news:
29
  summary = summarizer(user_news, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
30
  if lang == "Urdu":
31
- translation = translator(summary)[0]['translation_text']
32
  st.success("Summary in Urdu:")
33
- st.write(translation)
 
 
34
  else:
35
  st.success("Summary in English:")
36
  st.write(summary)
 
 
37
 
38
  # --- Precis Evaluation ---
39
  elif menu == "Precis Evaluation":
40
  st.header("✍️ Precis Evaluation Tool")
41
  precis_input = st.text_area("Enter your precis for evaluation:", height=200)
42
  if st.button("Evaluate Precis") and precis_input:
43
- corrected = grammar_corrector("grammar: " + precis_input)[
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from datetime import datetime
4
+ import base64
5
+ import os
6
 
7
  # Initialize models
8
  summarizer = pipeline("summarization")
9
+ translator_en_ur = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
10
+ translator_ur_en = pipeline("translation", model="Helsinki-NLP/opus-mt-ur-en")
11
  grammar_corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
12
 
13
+ # Set up page config
14
  st.set_page_config(page_title="CSS AI Assistant by Komal", layout="wide")
15
 
16
  st.title("πŸ“š CSS AI Assistant πŸ‡΅πŸ‡°")
17
  st.write("Helping students with news summaries, precis, essays & more β€” for free!")
18
 
19
+ # Sidebar Menu
20
  menu = st.sidebar.radio("Select Feature", [
21
  "Daily News Summary",
22
  "Precis Evaluation",
 
24
  "Saved Notes"
25
  ])
26
 
27
+ # File to save notes
28
+ NOTES_FILE = "saved_notes.txt"
29
+
30
+ def save_note(title, content):
31
+ with open(NOTES_FILE, "a", encoding='utf-8') as f:
32
+ f.write(f"\n## {title}\n{content}\n")
33
+
34
+ def load_notes():
35
+ if os.path.exists(NOTES_FILE):
36
+ with open(NOTES_FILE, "r", encoding='utf-8') as f:
37
+ return f.read()
38
+ return "No saved notes yet."
39
+
40
+ def generate_download_link(text, filename):
41
+ b64 = base64.b64encode(text.encode()).decode()
42
+ return f'<a href="data:file/txt;base64,{b64}" download="{filename}">πŸ“₯ Download Notes</a>'
43
+
44
  # --- Daily News Summary ---
45
  if menu == "Daily News Summary":
46
  st.header("πŸ“° AI-Powered News Summarizer")
 
50
  if st.button("Summarize") and user_news:
51
  summary = summarizer(user_news, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
52
  if lang == "Urdu":
53
+ translated = translator_en_ur(summary)[0]['translation_text']
54
  st.success("Summary in Urdu:")
55
+ st.write(translated)
56
+ if st.button("Save Urdu Summary"):
57
+ save_note(f"Urdu Summary - {datetime.now().date()}", translated)
58
  else:
59
  st.success("Summary in English:")
60
  st.write(summary)
61
+ if st.button("Save English Summary"):
62
+ save_note(f"English Summary - {datetime.now().date()}", summary)
63
 
64
  # --- Precis Evaluation ---
65
  elif menu == "Precis Evaluation":
66
  st.header("✍️ Precis Evaluation Tool")
67
  precis_input = st.text_area("Enter your precis for evaluation:", height=200)
68
  if st.button("Evaluate Precis") and precis_input:
69
+ corrected = grammar_corrector("grammar: " + precis_input)[0]['generated_text']
70
+ st.success("βœ… Corrected Precis:")
71
+ st.write(corrected)
72
+ if st.button("Save Precis"):
73
+ save_note(f"Precis - {datetime.now().date()}", corrected)
74
+
75
+ # --- Essay Feedback ---
76
+ elif menu == "Essay Feedback":
77
+ st.header("πŸ–‹οΈ Essay Evaluation Tool")
78
+ essay_input = st.text_area("Paste your essay here:", height=300)
79
+ if st.button("Evaluate Essay") and essay_input:
80
+ corrected = grammar_corrector("grammar: " + essay_input)[0]['generated_text']
81
+ st.success("βœ… Suggestions:")
82
+ st.write(corrected)
83
+ if st.button("Save Essay"):
84
+ save_note(f"Essay - {datetime.now().date()}", corrected)
85
+
86
+ # --- Saved Notes ---
87
+ elif menu == "Saved Notes":
88
+ st.header("πŸ’Ύ Saved Notes")
89
+ notes = load_notes()
90
+ st.markdown(notes)
91
+ st.markdown(generate_download_link(notes, "css_notes.txt"), unsafe_allow_html=True)