u-kuro commited on
Commit
ef4b65a
·
1 Parent(s): 5863ef1

Add favicon and update title with logo for sentiment analysis page

Browse files

- Added a favicon link to the HTML head for better branding.
- Updated the title section to include a U.S. flag logo alongside the title text.
- Introduced CSS variables for font sizes to maintain consistency and ease future adjustments.

.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.png filter=lfs diff=lfs merge=lfs -text
37
+ *.jpg filter=lfs diff=lfs merge=lfs -text
38
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
39
+ *.gif filter=lfs diff=lfs merge=lfs -text
app.ipynb CHANGED
@@ -24,15 +24,13 @@
24
  " * Running on all addresses (0.0.0.0)\n",
25
  " * Running on http://127.0.0.1:7860\n",
26
  " * Running on http://192.168.1.16:7860\n",
27
- "Press CTRL+C to quit\n",
28
- "192.168.1.16 - - [02/Jul/2025 12:01:12] \"GET / HTTP/1.1\" 200 -\n",
29
- "192.168.1.16 - - [02/Jul/2025 12:01:13] \"GET /favicon.ico HTTP/1.1\" 404 -\n"
30
  ]
31
  }
32
  ],
33
  "source": [
34
- "import os, torch\n",
35
- "from flask import Flask, request, jsonify, render_template\n",
36
  "from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
37
  "from dotenv import load_dotenv\n",
38
  "\n",
@@ -99,12 +97,41 @@
99
  " print(f\"Error: {str(e)}\")\n",
100
  " return jsonify({'error': 'An error occurred during prediction'}), 500\n",
101
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  "@app.route('/')\n",
103
  "def home():\n",
104
  " return render_template(\"index.html\")\n",
105
  "\n",
106
  "if __name__ == '__main__':\n",
107
- " app.run(host=\"0.0.0.0\", port=7860, debug=True)"
108
  ]
109
  },
110
  {
 
24
  " * Running on all addresses (0.0.0.0)\n",
25
  " * Running on http://127.0.0.1:7860\n",
26
  " * Running on http://192.168.1.16:7860\n",
27
+ "Press CTRL+C to quit\n"
 
 
28
  ]
29
  }
30
  ],
31
  "source": [
32
+ "import os, base64, torch\n",
33
+ "from flask import Flask, request, jsonify, render_template, Response\n",
34
  "from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
35
  "from dotenv import load_dotenv\n",
36
  "\n",
 
97
  " print(f\"Error: {str(e)}\")\n",
98
  " return jsonify({'error': 'An error occurred during prediction'}), 500\n",
99
  "\n",
100
+ "def load_base64_from_file(filename):\n",
101
+ " try:\n",
102
+ " with open(f'static/base64-images/{filename}.txt', 'r') as f:\n",
103
+ " return f.read().strip()\n",
104
+ " except FileNotFoundError:\n",
105
+ " return None\n",
106
+ " \n",
107
+ "@app.route('/static/favicon.png')\n",
108
+ "def favicon():\n",
109
+ " base64_data = load_base64_from_file('favicon')\n",
110
+ " if base64_data is None:\n",
111
+ " return \"Image not found\", 404\n",
112
+ " \n",
113
+ " image_data = base64.b64decode(base64_data)\n",
114
+ " response = Response(image_data, mimetype='image/png')\n",
115
+ " response.headers['Cache-Control'] = 'public, max-age=31536000'\n",
116
+ " return response\n",
117
+ "\n",
118
+ "@app.route('/static/images/us-flag.png')\n",
119
+ "def us_flag():\n",
120
+ " base64_data = load_base64_from_file('us-flag')\n",
121
+ " if base64_data is None:\n",
122
+ " return \"Image not found\", 404\n",
123
+ " \n",
124
+ " image_data = base64.b64decode(base64_data)\n",
125
+ " response = Response(image_data, mimetype='image/png')\n",
126
+ " response.headers['Cache-Control'] = 'public, max-age=31536000'\n",
127
+ " return response\n",
128
+ "\n",
129
  "@app.route('/')\n",
130
  "def home():\n",
131
  " return render_template(\"index.html\")\n",
132
  "\n",
133
  "if __name__ == '__main__':\n",
134
+ " app.run(host=\"0.0.0.0\", port=7860)"
135
  ]
136
  },
137
  {
app.py CHANGED
@@ -1,5 +1,5 @@
1
- import os, torch
2
- from flask import Flask, request, jsonify, render_template
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
  from dotenv import load_dotenv
5
 
@@ -28,7 +28,7 @@ def get_sentiment_score(text):
28
  max_length=128,
29
  return_tensors='pt'
30
  )
31
-
32
  outputs = model(**encoding)
33
  _, predicted = torch.max(outputs.logits, 1)
34
 
@@ -65,7 +65,36 @@ def predict():
65
  except Exception as e:
66
  print(f"Error: {str(e)}")
67
  return jsonify({'error': 'An error occurred during prediction'}), 500
 
 
 
 
 
 
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  @app.route('/')
70
  def home():
71
  return render_template("index.html")
 
1
+ import os, base64, torch
2
+ from flask import Flask, request, jsonify, render_template, Response
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
  from dotenv import load_dotenv
5
 
 
28
  max_length=128,
29
  return_tensors='pt'
30
  )
31
+
32
  outputs = model(**encoding)
33
  _, predicted = torch.max(outputs.logits, 1)
34
 
 
65
  except Exception as e:
66
  print(f"Error: {str(e)}")
67
  return jsonify({'error': 'An error occurred during prediction'}), 500
68
+
69
+ def load_base64_from_file(filename):
70
+ try:
71
+ with open(f'static/base64-images/{filename}.txt', 'r') as f:
72
+ return f.read().strip()
73
+ except FileNotFoundError:
74
+ return None
75
 
76
+ @app.route('/static/favicon.png')
77
+ def favicon():
78
+ base64_data = load_base64_from_file('favicon')
79
+ if base64_data is None:
80
+ return "Image not found", 404
81
+
82
+ image_data = base64.b64decode(base64_data)
83
+ response = Response(image_data, mimetype='image/png')
84
+ response.headers['Cache-Control'] = 'public, max-age=31536000'
85
+ return response
86
+
87
+ @app.route('/static/images/us-flag.png')
88
+ def us_flag():
89
+ base64_data = load_base64_from_file('us-flag')
90
+ if base64_data is None:
91
+ return "Image not found", 404
92
+
93
+ image_data = base64.b64decode(base64_data)
94
+ response = Response(image_data, mimetype='image/png')
95
+ response.headers['Cache-Control'] = 'public, max-age=31536000'
96
+ return response
97
+
98
  @app.route('/')
99
  def home():
100
  return render_template("index.html")
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
- gunicorn
2
- Flask
3
- transformers
4
- torch
 
 
1
+ gunicorn==23.0.0
2
+ Flask==3.0.3
3
+ transformers==4.46.3
4
+ torch==2.4.1
5
+ python-dotenv==1.0.1
static/base64-images/favicon.txt ADDED
The diff for this file is too large to render. See raw diff
 
static/base64-images/us-flag.txt ADDED
The diff for this file is too large to render. See raw diff
 
templates/index.html CHANGED
@@ -4,6 +4,7 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Sentiment Analysis</title>
 
7
  <style>
8
  * {
9
  margin: 0;
@@ -36,10 +37,17 @@
36
  }
37
 
38
  .title {
 
39
  color: #333;
40
- font-size: 2.5rem;
41
  font-weight: 700;
42
  }
 
 
 
 
 
 
43
 
44
  .subtitle {
45
  color: #666;
@@ -189,7 +197,7 @@
189
  }
190
 
191
  .title {
192
- font-size: 2rem;
193
  }
194
 
195
  .subtitle {
@@ -220,9 +228,8 @@
220
  </head>
221
  <body>
222
  <div class="container">
223
- <h1 class="title">🎭 Sentiment Analysis</h1>
224
  <p class="subtitle">Enter your text below to analyze its sentiment</p>
225
-
226
  <form class="sentiment-form" id="sentiment-form">
227
  <textarea
228
  class="text-input"
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Sentiment Analysis</title>
7
+ <link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
8
  <style>
9
  * {
10
  margin: 0;
 
37
  }
38
 
39
  .title {
40
+ --font-size: 2.5rem;
41
  color: #333;
42
+ font-size: var(--font-size);
43
  font-weight: 700;
44
  }
45
+
46
+ .logo {
47
+ height: var(--font-size);
48
+ width: auto;
49
+ vertical-align: middle;
50
+ }
51
 
52
  .subtitle {
53
  color: #666;
 
197
  }
198
 
199
  .title {
200
+ --font-size: 2rem;
201
  }
202
 
203
  .subtitle {
 
228
  </head>
229
  <body>
230
  <div class="container">
231
+ <h1 class="title"><img class="logo" src="{{ url_for('static', filename='images/us-flag.png') }}" alt="US Flag">&nbsp;U.S. Political Sentiment Analysis</h1>
232
  <p class="subtitle">Enter your text below to analyze its sentiment</p>
 
233
  <form class="sentiment-form" id="sentiment-form">
234
  <textarea
235
  class="text-input"