Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,12 @@ def upload_file():
|
|
| 31 |
file.save(file_path)
|
| 32 |
df = pd.read_csv(file_path)
|
| 33 |
summary = df.describe(include="all").to_html(classes="table table-striped")
|
| 34 |
-
return jsonify(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
return jsonify({"error": "Unsupported file type"}), 400
|
| 37 |
|
|
@@ -71,5 +76,30 @@ def chat():
|
|
| 71 |
)
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
if __name__ == "__main__":
|
| 75 |
-
app.run(host="0.0.0.0",
|
|
|
|
| 31 |
file.save(file_path)
|
| 32 |
df = pd.read_csv(file_path)
|
| 33 |
summary = df.describe(include="all").to_html(classes="table table-striped")
|
| 34 |
+
return jsonify(
|
| 35 |
+
{
|
| 36 |
+
"summary": summary,
|
| 37 |
+
"message": "File uploaded successfully. Let's see what we have here...",
|
| 38 |
+
}
|
| 39 |
+
)
|
| 40 |
else:
|
| 41 |
return jsonify({"error": "Unsupported file type"}), 400
|
| 42 |
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
|
| 79 |
+
@app.route("/explore", methods=["POST"])
|
| 80 |
+
def explore():
|
| 81 |
+
key = request.json.get("key")
|
| 82 |
+
matched_entry = answers.get(key)
|
| 83 |
+
|
| 84 |
+
if matched_entry:
|
| 85 |
+
response = matched_entry["answer"]["answer"]
|
| 86 |
+
justification = matched_entry["answer"]["justification"]
|
| 87 |
+
image_filename = f"{key}.jpg"
|
| 88 |
+
image_path = os.path.join(app.config["IMAGES_FOLDER"], image_filename)
|
| 89 |
+
|
| 90 |
+
if os.path.exists(image_path):
|
| 91 |
+
image_url = url_for("static", filename=f"images/{image_filename}")
|
| 92 |
+
else:
|
| 93 |
+
image_url = None
|
| 94 |
+
else:
|
| 95 |
+
response = "No more data to explore."
|
| 96 |
+
justification = None
|
| 97 |
+
image_url = None
|
| 98 |
+
|
| 99 |
+
return jsonify(
|
| 100 |
+
{"response": response, "justification": justification, "image_url": image_url}
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
if __name__ == "__main__":
|
| 105 |
+
app.run(host="0.0.0.0", debug=True, port=7860)
|