Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839#Downloading and importing all the modules required for this TaskBot v1 AIimport google.generativeai as genaiimport osimport jsonimport requestsfrom flask import Flask, request, jsonify, render_templateimport torch#Connect to index.htmlapp = Flask(__name__)@app.route("/")def index():return render_template("index.html")@app.route("/ask", methods=["POST"])def ask():#getting the question from the formquestion = request.form.get("question", "").strip()if not question:return jsonify({"error": "Please provide a question."}), 400genai.configure(api_key="AIzaSyA5FFcaVCfVmwf7X5C59n4xWc96xWR-A_4")try:# use Google's Gemini-2.0-Flash nodle for generating contentmodel = genai.GenerativeModel('gemini-2.0-flash')response = model.generate_content(f"You are TaskBot AI created and trained by Advay Singh and Astrumix. Remember that and just anser me this question in detail- {question}. And don't reply on that message. Just answer me the question.")answer = response.text# Log the question and answer for debuggingprint(f"Question: {question}\n------------------------- \n {answer} \n -------------------------")# Return the answer as JSONreturn jsonify({"answer": answer})except Exception as e:print(f"Error: {e}")return jsonify({"error": "An error occurred while processing your request."}), 500if __name__ == "__main__":app.run(port=5000, host="0.0.0.0")123456789101112131415161718192021222324252627282930313233343536373839#Downloading and importing all the modules required for this TaskBot v1 AIimport google.generativeai as genaiimport osimport jsonimport requestsfrom flask import Flask, request, jsonify, render_templateimport torch#Connect to index.htmlapp = Flask(__name__)@app.route("/")def index():return render_template("index.html")@app.route("/ask", methods=["POST"])def ask():#getting the question from the formquestion = request.form.get("question", "").strip()if not question:return jsonify({"error": "Please provide a question."}), 400genai.configure(api_key="AIzaSyA5FFcaVCfVmwf7X5C59n4xWc96xWR-A_4")try:# use Google's Gemini-2.0-Flash nodle for generating contentmodel = genai.GenerativeModel('gemini-2.0-flash')response = model.generate_content(f"You are TaskBot AI created and trained by Advay Singh and Astrumix. Remember that and just anser me this question in detail- {question}. And don't reply on that message. Just answer me the question.")answer = response.text# Log the question and answer for debuggingprint(f"Question: {question}\n------------------------- \n {answer} \n -------------------------")# Return the answer as JSONreturn jsonify({"answer": answer})except Exception as e:print(f"Error: {e}")return jsonify({"error": "An error occurred while processing your request."}), 500if __name__ == "__main__":app.run(port=7860, host="0.0.0.0")
app.py+39-39