Spaces:
Paused
Paused
File size: 2,339 Bytes
b9a9592 b3925a1 1bebd4d b9a9592 a86aeea b9a9592 5917eb8 b3925a1 695dec3 4c3e52e 695dec3 6b5b8ae b3925a1 5917eb8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
FROM python:3-slim
EXPOSE 7860
RUN pip install cloudscraper Flask --upgrade && \
apt-get update -y && \
apt-get install -y nodejs libnode108 && \
rm -rf /var/lib/apt/lists/*
COPY <<EOF /main.py
from flask import Flask, request, Response
import cloudscraper
scraper = cloudscraper.create_scraper(interpreter='nodejs')
app = Flask(__name__)
@app.route('/proxy/<scheme>:/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def proxy(scheme, url):
req_method = request.method
req_headers = {key: value for key, value in request.headers if key != 'Host'}
req_data = request.get_data()
resp = scraper.request(method=req_method,
url=f'{scheme}://{url}',
headers=req_headers,
data=req_data,
stream=True)
excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]
def generate():
for chunk in resp.iter_content(chunk_size=1):
yield chunk
return Response(generate(), status=resp.status_code, headers=headers)
@app.route('/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@app.route('/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def cf(url=""):
req_method = request.method
req_headers = {key: value for key, value in request.headers if key != 'Host'}
req_data = request.get_data()
resp = scraper.request(method=req_method,
url=f'https://chat.freegpts.org/{url}',
headers=req_headers,
data=req_data,
stream=True)
excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
headers = [(name, value) for (name, value) in resp.raw.headers.items()
if name.lower() not in excluded_headers]
def generate():
for chunk in resp.iter_content(chunk_size=1):
yield chunk
return Response(generate(), status=resp.status_code, headers=headers)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)
EOF
CMD python /main.py
|