AntDX316 commited on
Commit
a1ba68f
Β·
1 Parent(s): c0d0d43
Files changed (4) hide show
  1. .gitignore +35 -0
  2. README.md +38 -8
  3. app.py +6 -4
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ build/
9
+ develop-eggs/
10
+ dist/
11
+ downloads/
12
+ eggs/
13
+ .eggs/
14
+ lib/
15
+ lib64/
16
+ parts/
17
+ sdist/
18
+ var/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environment
24
+ venv/
25
+ ENV/
26
+
27
+ # IDE
28
+ .idea/
29
+ .vscode/
30
+ *.swp
31
+ *.swo
32
+
33
+ # OS specific
34
+ .DS_Store
35
+ Thumbs.db
README.md CHANGED
@@ -1,12 +1,42 @@
1
  ---
2
- title: Space
3
- emoji: πŸƒ
4
- colorFrom: indigo
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.20.1
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Flask Web App
3
+ emoji: 🌐
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ app_port: 7860
 
8
  pinned: false
9
  ---
10
 
11
+ # Flask Web Application for Hugging Face Spaces
12
+
13
+ This is a simple Flask web application deployed on Hugging Face Spaces. It provides:
14
+
15
+ - A clean web interface showing the current server time
16
+ - A REST API with endpoints for getting the current time and echoing data
17
+ - Cross-origin resource sharing (CORS) support for API access from other domains
18
+
19
+ ## API Endpoints
20
+
21
+ - `/api/time` - GET request that returns the current server time
22
+ - `/api/echo` - POST request that echoes back any JSON data sent to it
23
+
24
+ ## Local Development
25
+
26
+ To run this application locally:
27
+
28
+ 1. Install the required dependencies:
29
+ ```
30
+ pip install -r requirements.txt
31
+ ```
32
+
33
+ 2. Run the Flask application:
34
+ ```
35
+ python app.py
36
+ ```
37
+
38
+ 3. Open your browser and navigate to `http://localhost:7860`
39
+
40
+ ## Deployment
41
+
42
+ This application is configured for deployment on Hugging Face Spaces using Docker.
app.py CHANGED
@@ -1,8 +1,10 @@
1
  from flask import Flask, render_template, request, jsonify
 
2
  import os
3
  import datetime
4
 
5
  app = Flask(__name__)
 
6
 
7
  # Ensure templates directory exists
8
  os.makedirs('templates', exist_ok=True)
@@ -37,7 +39,7 @@ if __name__ == '__main__':
37
  <!DOCTYPE html>
38
  <html>
39
  <head>
40
- <title>Flask Web App</title>
41
  <style>
42
  body {
43
  font-family: Arial, sans-serif;
@@ -73,7 +75,7 @@ if __name__ == '__main__':
73
  </style>
74
  </head>
75
  <body>
76
- <h1>Welcome to Flask Web App</h1>
77
  <p>The current server time is: {{ current_time }}</p>
78
 
79
  <div class="container">
@@ -122,5 +124,5 @@ if __name__ == '__main__':
122
  </html>
123
  ''')
124
 
125
- # Run the Flask app
126
- app.run(debug=True)
 
1
  from flask import Flask, render_template, request, jsonify
2
+ from flask_cors import CORS
3
  import os
4
  import datetime
5
 
6
  app = Flask(__name__)
7
+ CORS(app) # Enable CORS for all routes
8
 
9
  # Ensure templates directory exists
10
  os.makedirs('templates', exist_ok=True)
 
39
  <!DOCTYPE html>
40
  <html>
41
  <head>
42
+ <title>Flask Web App on Hugging Face Spaces</title>
43
  <style>
44
  body {
45
  font-family: Arial, sans-serif;
 
75
  </style>
76
  </head>
77
  <body>
78
+ <h1>Welcome to Flask Web App on Hugging Face Spaces</h1>
79
  <p>The current server time is: {{ current_time }}</p>
80
 
81
  <div class="container">
 
124
  </html>
125
  ''')
126
 
127
+ # Run the Flask app with settings suitable for Hugging Face Spaces
128
+ app.run(host='0.0.0.0', port=7860, debug=True)
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  flask==2.3.3
2
  Werkzeug==2.3.7
 
 
 
 
1
  flask==2.3.3
2
  Werkzeug==2.3.7
3
+ flask-cors==4.0.0
4
+ transformers==4.25.1
5
+ torch==1.13.1