-
-
Save ken2190/037e6cd66e4f5521e6583c0e7049c37d to your computer and use it in GitHub Desktop.
Revisions
-
hoangdh revised this gist
Feb 24, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ if __name__ == '__main__': pip install flask bingart ``` - **Bước 2:** Lấy Cookie của Bing: - Dùng trình duyệt đăng nhập Tài khoản vào https://bing.com - Bấm F12, chọn tab **Console** - Thực hiện lệnh: `cookieStore.get("_U").then(result => console.log(result.value))` - Lấy thông tin và điền vào biến `myCookie` trong script -
hoangdh revised this gist
Feb 24, 2025 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,6 +52,7 @@ pip install flask bingart - **Bước 2**: Điền Cookie vừa lấy và sao chép script trên vào máy chủ của bạn - **Bước 3**: Chạy script Giả sử, ta đã đưa script vào thư mục `/opt/bingart-api.py` ``` -
hoangdh revised this gist
Feb 24, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Tạo hình ảnh bằng Bing Art AI của Microsoft thông qua API ## Script API -
hoangdh revised this gist
Feb 24, 2025 . 1 changed file with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Tạo hình ảnh bằng Bing Art AI của Microsoft bằng API ## Script API ```python @@ -16,7 +18,7 @@ def generate_images(): return jsonify({"error": "Please provide a prompt via the GET parameter 'prompt'"}), 400 # Replace 'myCooko' with your valid _U cookie value bing_art = BingArt(auth_cookie_U=myCookie) images = [] try: results = bing_art.generate_images(prompt) @@ -48,7 +50,7 @@ pip install flask bingart  - **Bước 2**: Điền Cookie vừa lấy và sao chép script trên vào máy chủ của bạn - **Bước 3**: Chạy script Giả sử, ta đã đưa script vào thư mục `/opt/bingart-api.py` @@ -66,5 +68,12 @@ Truy cập vào địa chỉ bằng trình duyệt như sau: http://127.0.0.1:5000/bingart?prompt=a cute dog ``` Kết quả trả về:  ## Tham khảo: - Code: Genini AI - https://github.com/DedInc/bingart -
hoangdh revised this gist
Feb 24, 2025 . 1 changed file with 6 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,29 +13,22 @@ app = Flask(__name__) def generate_images(): prompt = request.args.get('prompt') if not prompt: return jsonify({"error": "Please provide a prompt via the GET parameter 'prompt'"}), 400 # Replace 'myCooko' with your valid _U cookie value bing_art = BingArt(auth_cookie_U='myCooko') images = [] try: results = bing_art.generate_images(prompt) for image in results['images']: imageUrl = image['url'] images.append(imageUrl) except Exception as e: return jsonify({"error": f"An error occurred while generating images: {str(e)}", "prompt": prompt}), 500 finally: bing_art.close_session() return jsonify({"images": list(set(images)), "prompt": prompt}) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=5000) -
hoangdh created this gist
Feb 24, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ ## Script API ```python from flask import Flask, request, jsonify, render_template from bingart import BingArt # Replace your cookie myCookie = '' app = Flask(__name__) @app.route('/bingart', methods=['GET']) def generate_images(): prompt = request.args.get('prompt') if not prompt: if request.accept_mimetypes.accept_html: return render_template('index.html', error="Please provide a prompt via the GET parameter 'prompt'", images=[], prompt="") else: return jsonify({"error": "Please provide a prompt via the GET parameter 'prompt'"}), 400 # Replace 'myCooko' with your valid _U cookie value bing_art = BingArt(auth_cookie_U=myCookie) images = [] error_message = None try: results = bing_art.generate_images(prompt) for image in results['images']: imageUrl = image['url'] images.append(imageUrl) except Exception as e: error_message = f"An error occurred while generating images: {str(e)}" if not request.accept_mimetypes.accept_html: return jsonify({"error": error_message, "prompt": prompt}), 500 if request.accept_mimetypes.accept_html: return render_template('index.html', images=list(set(images)), prompt=prompt, error=error_message) else: return jsonify({"images": list(set(images)), "prompt": prompt, "error": error_message}) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=5000) ``` ## Cài đặt môi trường - **Bước 1**: Cài đặt các thư viện cần thiết ``` pip install flask bingart ``` - **Bước 2:** Lấy Cookie của Bing: - Dùng trình duyệt đăng nhập vào https://bing.com - Bấm F12, chọn tab **Console** - Thực hiện lệnh: `cookieStore.get("_U").then(result => console.log(result.value))` - Lấy thông tin và điền vào biến `myCookie` trong script  - **Bước 2**: Sao chép script trên vào máy chủ của bạn - **Bước 3**: Chạy script Giả sử, ta đã đưa script vào thư mục `/opt/bingart-api.py` ``` python3 /opt/bingart-api.py ``` ## Sử dụng: Giả sử, ta chạy ứng dụng trên localhost với địa chỉ `http://127.0.0.1:5000`. Truy cập vào địa chỉ bằng trình duyệt như sau: ``` http://127.0.0.1:5000/bingart?prompt=a cute dog ```