JuanJoseMV commited on
Commit
0d5a7ab
Β·
1 Parent(s): 5a24282

First commit

Browse files
.gitignore ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ *.env
7
+ *.venv
8
+ *.egg
9
+ *.egg-info/
10
+ dist/
11
+ build/
12
+ *.log
13
+
14
+ # Virtual Environment
15
+ .venv/
16
+
17
+ # VSCode
18
+ .vscode/
19
+ *.code-workspace
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: News Time Series Anomaly Detection
3
- emoji: πŸ‘€
4
- colorFrom: purple
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.29.0
8
  app_file: app.py
 
1
  ---
2
  title: News Time Series Anomaly Detection
3
+ emoji: πŸ“‰
4
+ colorFrom: green
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.29.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.visualization import plot_time_series
3
+
4
+ PROJECT_HTML_PATH = "sections/project_description.html"
5
+ WELCOME_HTML_PATH = "sections/welcome_section.html"
6
+ DEMO_HTML_PATH = "sections/demo_section.html"
7
+ TRY_IT_YOURSELF_HTML_PATH = "sections/try_it_yourself.html"
8
+ CSS_FILE_PATH = "sections/styles/blocks.css"
9
+ ANOMALY_METHODS = ["LSTM", "ARIMA", "IQR"]
10
+
11
+ with open(PROJECT_HTML_PATH, "r") as file:
12
+ project_description_html = file.read()
13
+ with open(WELCOME_HTML_PATH, "r") as file:
14
+ welcome_html = file.read()
15
+ with open(DEMO_HTML_PATH, "r") as file:
16
+ demo_section_html = file.read()
17
+ with open(TRY_IT_YOURSELF_HTML_PATH, "r") as file:
18
+ try_it_yourself_html = file.read()
19
+
20
+ with open(CSS_FILE_PATH, "r") as css_file:
21
+ blocks_css = css_file.read()
22
+
23
+ with gr.Blocks(css=blocks_css) as demo:
24
+ gr.HTML(project_description_html)
25
+ gr.Markdown(welcome_html)
26
+ gr.Markdown(demo_section_html)
27
+ gr.HTML(try_it_yourself_html)
28
+
29
+ file_input = gr.File(label="Upload Time Series CSV")
30
+ plot_btn = gr.Button("Plot Time Series")
31
+ plot_output = gr.Plot(label="Time Series Plot")
32
+
33
+ method_input = gr.Dropdown(choices=ANOMALY_METHODS, label="Select Anomaly Detection Method", value="LSTM")
34
+ analyze_btn = gr.Button("Detect Anomalies")
35
+ anomaly_output = gr.Plot(label="Anomaly Detection Results")
36
+
37
+ plot_btn.click(
38
+ fn=plot_time_series,
39
+ inputs=[file_input],
40
+ outputs=[plot_output]
41
+ )
42
+
43
+ # analyze_btn.click(
44
+ # fn=detect_anomalies,
45
+ # inputs=[file_input, method_input],
46
+ # outputs=[anomaly_output]
47
+ # )
48
+
49
+ demo.launch(show_api=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==5.29.0
2
+ plotly==6.0.1
sections/demo_section.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <section>
2
+ <h2>πŸ” What This Demo Does</h2>
3
+ <ul>
4
+ <li><strong>πŸ“Š Time Series Visualization</strong><br>Upload your CSV file containing dates and disease mention counts, and visualize the temporal patterns using interactive Plotly charts.</li>
5
+ <li><strong>πŸ” Anomaly Detection</strong><br>Choose from multiple detection methods to identify unusual patterns in your time series:
6
+ <ul>
7
+ <li><strong>LSTM:</strong> Uses deep learning to model sequential data and detect anomalies based on deviations from predicted patterns</li>
8
+ <li><strong>ARIMA:</strong> Employs statistical methods to forecast time series and identify anomalies by comparing actual values to predictions</li>
9
+ <li><strong>IQR:</strong> Flags anomalies by identifying data points that fall outside the interquartile range</li>
10
+ </ul>
11
+ </li>
12
+ </ul>
13
+ </section>
sections/project_description.html ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>TrustAlert: News Anomaly Detection</title>
7
+ <style>
8
+ body {
9
+ font-family: 'Segoe UI', sans-serif;
10
+ line-height: 1.6;
11
+ margin: 0;
12
+ padding: 0;
13
+ color: #333;
14
+ }
15
+ header {
16
+ background-color: #2a4d69;
17
+ color: white !important;
18
+ padding: 20px;
19
+ text-align: center;
20
+ }
21
+ section {
22
+ padding: 20px;
23
+ margin: 20px auto;
24
+ color-scheme: light;
25
+ }
26
+ ul {
27
+ padding-left: 20px;
28
+ }
29
+ body, p, ul, li, strong, code {
30
+ color: #333;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <header>
36
+ <h1 style="color:white !important;">πŸ›‘οΈ TrustAlert: News Time Series Anomaly Detection</h1>
37
+ <p style="color:white !important;">Detecting anomalies in disease-related news coverage using advanced time series analysis</p>
38
+ </header>
39
+ <section>
40
+ <p>This tool analyzes temporal patterns in disease-related news coverage to identify potential outbreaks or unusual events. By detecting anomalies in the frequency of disease mentions, we can help public health officials spot emerging health concerns early.</p>
41
+ </section>
42
+ </body>
43
+ </html>
sections/styles/blocks.css ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: 'Segoe UI', sans-serif;
3
+ line-height: 1.6;
4
+ margin: 0;
5
+ padding: 0;
6
+ color: #333;
7
+ }
8
+
9
+ h1, h2 {
10
+ font-family: 'Segoe UI', sans-serif;
11
+ color: #2a4d69;
12
+ }
13
+
14
+ h3 {
15
+ font-family: 'Segoe UI', sans-serif;
16
+ color: #4b86b4;
17
+ }
18
+
19
+ .gr-button {
20
+ background: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
21
+ font-weight: bold;
22
+ border-radius: 12px;
23
+ padding: 10px 16px;
24
+ }
25
+
26
+ .gr-button:hover {
27
+ background: #00c9fe;
28
+ }
29
+
30
+ textarea {
31
+ border-radius: 10px;
32
+ border: 1px solid #ccc;
33
+ padding: 12px;
34
+ }
35
+
36
+ .gr-box {
37
+ border-radius: 10px;
38
+ box-shadow: 0 2px 5px rgba(0,0,0,0.05);
39
+ }
sections/try_it_yourself.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <section>
2
+ <h2>πŸ§ͺ Try It Yourself</h2>
3
+ <ul>
4
+ <li>πŸ“ˆ Upload a CSV file with two columns: dates in the first column and disease mention counts in the second</li>
5
+ <li>🎯 Click "Plot Time Series" to visualize your data</li>
6
+ <li>πŸ” Select an anomaly detection method from the dropdown</li>
7
+ <li>⚑ Click "Detect Anomalies" to identify unusual patterns in your time series</li>
8
+ </ul>
9
+ <p>This tool combines time series analysis and anomaly detection to help identify potential disease outbreaks based on news coverage patterns. πŸ’‘</p>
10
+ </section>
sections/welcome_section.html ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <section>
2
+ <h2>Welcome! πŸ‘‹</h2>
3
+ <p>This demo is part of the <strong>TrustAlert: Empowering Public Health with Real-Time Insights and Future Preparedness</strong> project, where we detect unusual patterns in disease-related news coverage that might indicate potential outbreaks or emerging health concerns.</p>
4
+ <p><strong>AI for early health alerts</strong>, powered by time series analysis and anomaly detection.</p>
5
+ </section>
src/visualization.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import plotly.express as px
3
+
4
+
5
+ def plot_time_series(file):
6
+ """
7
+ Plots a time series graph from a CSV file.
8
+
9
+ This function reads the CSV file and generates a line plot
10
+ showing the disease mentions over time.
11
+
12
+ """
13
+ df = pd.read_csv(file.name)
14
+ fig = px.line(
15
+ df,
16
+ x=df.columns[0],
17
+ y=df.columns[1],
18
+ title='Disease Mentions Over Time'
19
+ )
20
+ return fig