# app.py from flask import Flask, request, jsonify import openai app = Flask(__name__) # API Key yahan enter karo openai.api_key = "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" @app.route("/", methods=["GET"]) def home(): return "

ChatGPT Query Service

Enter your query at /query endpoint.

" @app.route("/query", methods=["POST"]) def query(): data = request.get_json() query_text = data.get("query", "") if not query_text: return jsonify({"error": "Query text is required"}), 400 try: response = openai.Completion.create( engine="text-davinci-003", prompt=query_text, max_tokens=100 ) answer = response.choices[0].text.strip() return jsonify({"query": query_text, "answer": answer}) except Exception as e: return jsonify({"error": str(e)}), 500 if __name__ == "__main__": app.run(host="0.0.0.0", port=8000)