Spaces:
Runtime error
Runtime error
Upload 5 files
Browse files- .gitignore +159 -0
- Procfile +1 -0
- README.md +20 -8
- main.py +30 -0
- requirements.txt +21 -0
.gitignore
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Created by https://www.toptal.com/developers/gitignore/api/python
|
3 |
+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
4 |
+
|
5 |
+
### Python ###
|
6 |
+
# Byte-compiled / optimized / DLL files
|
7 |
+
__pycache__/
|
8 |
+
*.py[cod]
|
9 |
+
*$py.class
|
10 |
+
|
11 |
+
# C extensions
|
12 |
+
*.so
|
13 |
+
|
14 |
+
# Distribution / packaging
|
15 |
+
.Python
|
16 |
+
build/
|
17 |
+
develop-eggs/
|
18 |
+
dist/
|
19 |
+
downloads/
|
20 |
+
eggs/
|
21 |
+
.eggs/
|
22 |
+
lib/
|
23 |
+
lib64/
|
24 |
+
parts/
|
25 |
+
sdist/
|
26 |
+
var/
|
27 |
+
wheels/
|
28 |
+
pip-wheel-metadata/
|
29 |
+
share/python-wheels/
|
30 |
+
*.egg-info/
|
31 |
+
.installed.cfg
|
32 |
+
*.egg
|
33 |
+
MANIFEST
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
# Usually these files are written by a python script from a template
|
37 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
38 |
+
*.manifest
|
39 |
+
*.spec
|
40 |
+
|
41 |
+
# Installer logs
|
42 |
+
pip-log.txt
|
43 |
+
pip-delete-this-directory.txt
|
44 |
+
|
45 |
+
# Unit test / coverage reports
|
46 |
+
htmlcov/
|
47 |
+
.tox/
|
48 |
+
.nox/
|
49 |
+
.coveage
|
50 |
+
.coverage.*
|
51 |
+
.cache
|
52 |
+
nosetests.xml
|
53 |
+
coverage.xml
|
54 |
+
*.cover
|
55 |
+
*.py,cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
pytestdebug.log
|
59 |
+
|
60 |
+
# Translations
|
61 |
+
*.mo
|
62 |
+
*.pot
|
63 |
+
|
64 |
+
# Django stuff:
|
65 |
+
*.log
|
66 |
+
local_settings.py
|
67 |
+
db.sqlite3
|
68 |
+
db.sqlite3-journal
|
69 |
+
|
70 |
+
# Flask stuff:
|
71 |
+
instance/
|
72 |
+
.webassets-cache
|
73 |
+
|
74 |
+
# Scrapy stuff:
|
75 |
+
.scrapy
|
76 |
+
|
77 |
+
# Sphinx documentation
|
78 |
+
docs/_build/
|
79 |
+
doc/_build/
|
80 |
+
|
81 |
+
# PyBuilder
|
82 |
+
target/
|
83 |
+
|
84 |
+
# Jupyter Notebook
|
85 |
+
.ipynb_checkpoints
|
86 |
+
|
87 |
+
# IPython
|
88 |
+
profile_default/
|
89 |
+
ipython_config.py
|
90 |
+
|
91 |
+
# pyenv
|
92 |
+
.python-version
|
93 |
+
|
94 |
+
# pipenv
|
95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
98 |
+
# install all needed dependencies.
|
99 |
+
#Pipfile.lock
|
100 |
+
|
101 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
102 |
+
__pypackages__/
|
103 |
+
|
104 |
+
# Celery stuff
|
105 |
+
celerybeat-schedule
|
106 |
+
celerybeat.pid
|
107 |
+
|
108 |
+
# SageMath parsed files
|
109 |
+
*.sage.py
|
110 |
+
|
111 |
+
# Environments
|
112 |
+
.env
|
113 |
+
.venv
|
114 |
+
env/
|
115 |
+
venv/
|
116 |
+
ENV/
|
117 |
+
env.bak/
|
118 |
+
venv.bak/
|
119 |
+
pythonenv*
|
120 |
+
|
121 |
+
# Spyder project settings
|
122 |
+
.spyderproject
|
123 |
+
.spyproject
|
124 |
+
|
125 |
+
# Rope project settings
|
126 |
+
.ropeproject
|
127 |
+
|
128 |
+
# mkdocs documentation
|
129 |
+
/site
|
130 |
+
|
131 |
+
# mypy
|
132 |
+
.mypy_cache/
|
133 |
+
.dmypy.json
|
134 |
+
dmypy.json
|
135 |
+
|
136 |
+
# Pyre type checker
|
137 |
+
.pyre/
|
138 |
+
|
139 |
+
# pytype static type analyzer
|
140 |
+
.pytype/
|
141 |
+
|
142 |
+
# profiling data
|
143 |
+
.prof
|
144 |
+
|
145 |
+
# Virtualenv
|
146 |
+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
147 |
+
.Python
|
148 |
+
[Bb]in
|
149 |
+
[Ii]nclude
|
150 |
+
[Ll]ib
|
151 |
+
[Ll]ib64
|
152 |
+
[Ll]ocal
|
153 |
+
[Ss]cripts
|
154 |
+
pyvenv.cfg
|
155 |
+
.venv
|
156 |
+
pip-selfcheck.json
|
157 |
+
|
158 |
+
|
159 |
+
# End of https://www.toptal.com/developers/gitignore/api/python
|
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: gunicorn main:app
|
README.md
CHANGED
@@ -1,11 +1,23 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
pinned: false
|
8 |
-
license: apache-2.0
|
9 |
---
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Flask
|
3 |
+
description: A popular minimal server framework for Python
|
4 |
+
tags:
|
5 |
+
- python
|
6 |
+
- flask
|
|
|
|
|
7 |
---
|
8 |
|
9 |
+
# Python Flask Example
|
10 |
+
|
11 |
+
This is a [Flask](https://flask.palletsprojects.com/en/1.1.x/) app that serves a simple JSON response.
|
12 |
+
|
13 |
+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/zUcpux)
|
14 |
+
|
15 |
+
## β¨ Features
|
16 |
+
|
17 |
+
- Python
|
18 |
+
- Flask
|
19 |
+
|
20 |
+
## πββοΈ How to use
|
21 |
+
|
22 |
+
- Install Python requirements `pip install -r requirements.txt`
|
23 |
+
- Start the server for development `python3 main.py`
|
main.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify, url_for
|
2 |
+
from googletrans import Translator
|
3 |
+
import os
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
translator = Translator(service_urls=['translate.google.com'])
|
7 |
+
|
8 |
+
@app.route('/')
|
9 |
+
def home():
|
10 |
+
return render_template('index.html')
|
11 |
+
|
12 |
+
@app.route('/translate', methods=['POST'])
|
13 |
+
def translate_text():
|
14 |
+
data = request.get_json()
|
15 |
+
text = data.get('text')
|
16 |
+
target_lang = data.get('target_lang')
|
17 |
+
|
18 |
+
if not text or not target_lang:
|
19 |
+
return jsonify({'error': 'Missing required parameters'}), 400
|
20 |
+
|
21 |
+
try:
|
22 |
+
translation = translator.translate(text, dest=target_lang)
|
23 |
+
translated_text = translation.text
|
24 |
+
return jsonify({'translated_text': translated_text}), 200
|
25 |
+
except Exception as e:
|
26 |
+
return jsonify({'error': str(e)}), 500
|
27 |
+
|
28 |
+
if __name__ == '__main__':
|
29 |
+
app.run(debug=True, port=os.getenv("PORT", default=5000))
|
30 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blinker==1.6.2
|
2 |
+
certifi==2023.5.7
|
3 |
+
chardet==3.0.4
|
4 |
+
click==8.1.3
|
5 |
+
Flask==2.3.2
|
6 |
+
gunicorn==20.0.4
|
7 |
+
googletrans==4.0.0rc1
|
8 |
+
h11==0.9.0
|
9 |
+
h2==3.2.0
|
10 |
+
hpack==3.0.0
|
11 |
+
hstspreload==2023.1.1
|
12 |
+
httpcore==0.9.1
|
13 |
+
httpx==0.13.3
|
14 |
+
hyperframe==5.2.0
|
15 |
+
idna==2.10
|
16 |
+
itsdangerous==2.1.2
|
17 |
+
Jinja2==3.1.2
|
18 |
+
MarkupSafe==2.1.3
|
19 |
+
rfc3986==1.5.0
|
20 |
+
sniffio==1.3.0
|
21 |
+
Werkzeug==2.3.6
|