import os import requests from flask import Flask, request, jsonify app = Flask(__name__) # The HTML and CSS for the mobile-friendly user interface. # The design is modern, interactive, and uses Tailwind CSS. # You can modify the design from here. # (هنا تبدأ الواجهة الأمامية للتطبيق، وهي مصممة بأسلوب عصري ومناسب للجوالات باستخدام Tailwind CSS) html_template = """ Worm Chat GPT

Worm Chat GPT

أهلاً بك، أرسل طلبك وسيتم تنفيذه

""" # The HTML and CSS for the mobile-friendly user interface ends here. @app.route('/') def index(): """Renders the main HTML page for the web application.""" return html_template @app.route('/api/process', methods=['POST']) def process_text(): """Handles text processing requests.""" try: # Get the text from the request body data = request.get_json() user_text = data.get('text', '').strip() if not user_text: return jsonify({"error": "الرجاء إرسال نص صالح."}), 400 # Construct the URL for the external API api_url = f'https://dev-pycodz-blackbox.pantheonsite.io/DEvZ44d/DarkCode.php?text={user_text}' # Make the GET request to the external API response = requests.get(api_url) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) # The external API response is the text we need processed_text = response.text # Return the processed text in a JSON format return jsonify({"result": processed_text}) except requests.exceptions.RequestException as e: # Handle network or HTTP errors when connecting to the external API return jsonify({"error": f"حدث خطأ في الاتصال بالخدمة الخارجية: {str(e)}"}), 500 except Exception as e: # Handle any other unexpected errors return jsonify({"error": f"حدث خطأ غير متوقع: {str(e)}"}), 500 # This block is crucial for running the application on Hugging Face Spaces if __name__ == "__main__": app.run(host='0.0.0.0', port=int(os.environ.get("PORT", 5000)))