from flask import Flask, request, jsonify, rendertemplate import os import subprocess…
- User
from flask import Flask, request, jsonify, render_template import os import subprocess
app = Flask(name)
Sample data for demonstration
product_data = [ {"id": 1, "name": "Skinny Blue Jeans", "price": "50", "image": "https://example.com/image1.jpg"}, {"id": 2, "name": "Slim Fit Blue Jeans", "price": "60", "image": "https://example.com/image2.jpg"} ]
def run_chatgpt_model(input_text): """ Run the ChatGPT model from the
yuntian-deng/ChatGPTrepository and return the output. """ try: # Path to the ChatGPT repository chatgpt_path = "yuntian-deng/ChatGPT"# Command to run the ChatGPT model with input process = subprocess.Popen( ["python", "run.py", input_text], cwd=chatgpt_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) output, error = process.communicate() if error: print(f"Error: {error}") return "Sorry, something went wrong with ChatGPT." return output.strip() except Exception as e: print(f"Exception: {e}") return "Sorry, I couldn't process your request."@app.route("/") def home(): return render_template("index.html")
@app.route("/chat", methods=["POST"]) def chatbot(): user_input = request.json.get("message") response = {}
# Generate a response using ChatGPT gpt_response = run_chatgpt_model(user_input) # Handle specific keywords for product-related queries if "jeans" in user_input.lower(): response["message"] = "Sure! Can you tell me more? What model or style are you looking for—skinny, straight, or bootcut?" elif "skinny" in user_input.lower(): response["message"] = "Got it. Any color preference?" elif "blue" in user_input.lower(): response["message"] = "Here are some skinny blue jeans I found." response["products"] = product_data else: response["message"] = gpt_response # Use ChatGPT-generated response for general queries return jsonify(response)if name == "main": app.run(debug=True)
- Assistant
- User
yuntian-deng/ChatGPT how to this run
- Assistant