zykrix commited on
Commit
691b69e
·
1 Parent(s): cc7493a

fix: replacing streamlit with flask

Browse files
Files changed (6) hide show
  1. app.py +30 -30
  2. render.yaml +2 -6
  3. requirements.txt +3 -0
  4. start.sh +2 -6
  5. static/style.css +43 -0
  6. templates/index.html +49 -0
app.py CHANGED
@@ -1,41 +1,41 @@
1
- import streamlit as st
 
2
  from modules.summarizer import summarize_text
3
  from modules.classifier import classify_text
4
  from modules.event_detector import detect_events
5
  from modules.utils import read_pdf, fetch_article_from_url
6
 
7
- st.set_page_config(page_title="NLP Assistant", layout="wide")
8
- st.title("NLP Assistant - Summarization, Classification & Event Detection")
9
 
10
- tab1, tab2, tab3 = st.tabs(["Summarization", "News Classification", "Event Detection"])
 
 
11
 
12
- with tab1:
13
- st.subheader("Summarize Text, PDF, or URL")
14
- text_input = st.text_area("Paste Article", height=300)
15
- pdf_input = st.file_uploader("Upload PDF", type="pdf")
16
- url_input = st.text_input("Paste Article URL")
 
 
 
 
 
17
 
18
- if st.button("Summarize"):
19
- if url_input.strip():
20
- content = fetch_article_from_url(url_input)
21
- elif pdf_input:
22
- content = read_pdf(pdf_input)
23
- else:
24
- content = text_input
25
 
26
- with st.spinner("Summarizing..."):
27
- st.text_area("Summary", summarize_text(content), height=400)
 
 
 
28
 
29
- with tab2:
30
- st.subheader("Classify News Content")
31
- classify_input = st.text_area("Enter News Content", height=300)
32
- if st.button("Classify"):
33
- with st.spinner("Classifying..."):
34
- st.success(classify_text(classify_input))
35
 
36
- with tab3:
37
- st.subheader("Detect Key Events from Text")
38
- event_input = st.text_area("Enter Article or Paragraph", height=300)
39
- if st.button("Detect Events"):
40
- with st.spinner("Detecting..."):
41
- st.success(detect_events(event_input))
 
1
+ # app.py
2
+ from flask import Flask, request, render_template
3
  from modules.summarizer import summarize_text
4
  from modules.classifier import classify_text
5
  from modules.event_detector import detect_events
6
  from modules.utils import read_pdf, fetch_article_from_url
7
 
8
+ app = Flask(__name__)
 
9
 
10
+ @app.route('/')
11
+ def home():
12
+ return render_template("index.html")
13
 
14
+ @app.route('/summarize', methods=['POST'])
15
+ def summarize():
16
+ content = ""
17
+ if 'url_input' in request.form and request.form['url_input'].strip():
18
+ content = fetch_article_from_url(request.form['url_input'])
19
+ elif 'pdf_input' in request.files and request.files['pdf_input'].filename:
20
+ pdf_file = request.files['pdf_input']
21
+ content = read_pdf(pdf_file)
22
+ else:
23
+ content = request.form.get('text_input', '')
24
 
25
+ summary = summarize_text(content)
26
+ return render_template("index.html", summary=summary)
 
 
 
 
 
27
 
28
+ @app.route('/classify', methods=['POST'])
29
+ def classify():
30
+ text = request.form.get('classify_input', '')
31
+ classification = classify_text(text)
32
+ return render_template("index.html", classification=classification)
33
 
34
+ @app.route('/events', methods=['POST'])
35
+ def events():
36
+ text = request.form.get('event_input', '')
37
+ events = detect_events(text)
38
+ return render_template("index.html", events=events)
 
39
 
40
+ if __name__ == '__main__':
41
+ app.run(debug=True, port=10000, host='0.0.0.0')
 
 
 
 
render.yaml CHANGED
@@ -1,11 +1,7 @@
1
  services:
2
  - type: web
3
- name: nlp-assistant
4
  env: python
5
- plan: starter
6
- region: oregon
7
  buildCommand: pip install -r requirements.txt
8
  startCommand: ./start.sh
9
- envVars:
10
- - key: PYTHON_VERSION
11
- value: 3.10
 
1
  services:
2
  - type: web
3
+ name: nlp-assistant-flask
4
  env: python
 
 
5
  buildCommand: pip install -r requirements.txt
6
  startCommand: ./start.sh
7
+ plan: free
 
 
requirements.txt CHANGED
@@ -13,3 +13,6 @@ torch==2.6.0
13
  numpy==1.26.4
14
  lxml_html_clean==0.1.1
15
  lxml==5.3.1
 
 
 
 
13
  numpy==1.26.4
14
  lxml_html_clean==0.1.1
15
  lxml==5.3.1
16
+ flask==2.3.3
17
+ beautifulsoup4
18
+ requests
start.sh CHANGED
@@ -1,7 +1,3 @@
1
  #!/bin/bash
2
-
3
- # Ensure the PORT Render expects is used
4
- export PORT=${PORT:-8501}
5
-
6
- # Run Streamlit binding to the correct host and port
7
- streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
 
1
  #!/bin/bash
2
+ export PORT=10000
3
+ exec gunicorn app:app --bind 0.0.0.0:$PORT --timeout 300
 
 
 
 
static/style.css ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, sans-serif;
3
+ margin: 30px;
4
+ background-color: #f8f9fa;
5
+ color: #333;
6
+ }
7
+
8
+ h1 {
9
+ text-align: center;
10
+ color: #0056b3;
11
+ }
12
+
13
+ .section {
14
+ background: white;
15
+ padding: 20px;
16
+ margin: 20px 0;
17
+ border-radius: 12px;
18
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
19
+ }
20
+
21
+ textarea {
22
+ width: 100%;
23
+ height: 120px;
24
+ padding: 10px;
25
+ margin-top: 10px;
26
+ border: 1px solid #ccc;
27
+ border-radius: 6px;
28
+ }
29
+
30
+ button {
31
+ margin-top: 10px;
32
+ padding: 8px 20px;
33
+ background-color: #007bff;
34
+ color: white;
35
+ border: none;
36
+ border-radius: 6px;
37
+ cursor: pointer;
38
+ }
39
+
40
+ button:hover {
41
+ background-color: #0056b3;
42
+ }
43
+
templates/index.html ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>NLP Assistant</title>
6
+ <link rel="stylesheet" href="/static/styles.css">
7
+ </head>
8
+ <body>
9
+ <h1>NLP Assistant</h1>
10
+
11
+ <div class="section">
12
+ <h2>Summarization</h2>
13
+ <form action="/summarize" method="POST" enctype="multipart/form-data">
14
+ <textarea name="text_input" placeholder="Paste article text..."></textarea><br>
15
+ <input type="file" name="pdf_input"><br>
16
+ <input type="text" name="url_input" placeholder="Paste article URL..."><br>
17
+ <button type="submit">Summarize</button>
18
+ </form>
19
+ {% if summary %}
20
+ <h3>Summary:</h3>
21
+ <textarea readonly>{{ summary }}</textarea>
22
+ {% endif %}
23
+ </div>
24
+
25
+ <div class="section">
26
+ <h2>Classification</h2>
27
+ <form action="/classify" method="POST">
28
+ <textarea name="classify_input" placeholder="Enter news content..."></textarea><br>
29
+ <button type="submit">Classify</button>
30
+ </form>
31
+ {% if classification %}
32
+ <h3>Category:</h3>
33
+ <p>{{ classification }}</p>
34
+ {% endif %}
35
+ </div>
36
+
37
+ <div class="section">
38
+ <h2>Event Detection</h2>
39
+ <form action="/events" method="POST">
40
+ <textarea name="event_input" placeholder="Enter article or paragraph..."></textarea><br>
41
+ <button type="submit">Detect Events</button>
42
+ </form>
43
+ {% if events %}
44
+ <h3>Detected Events:</h3>
45
+ <p>{{ events }}</p>
46
+ {% endif %}
47
+ </div>
48
+ </body>
49
+ </html>