Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import sample_rust
|
| 4 |
import os
|
|
@@ -12,23 +12,28 @@ CORS(app)
|
|
| 12 |
|
| 13 |
@app.route("/")
|
| 14 |
def index():
|
| 15 |
-
return "
|
| 16 |
|
| 17 |
@app.route("/ask", methods=["POST"])
|
| 18 |
def ask():
|
| 19 |
try:
|
| 20 |
-
data = request.get_json()
|
| 21 |
question = data.get("question", "World")
|
| 22 |
|
| 23 |
logging.info(f"Received question: {question}")
|
| 24 |
-
result = sample_rust.hello(question) #
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
except Exception as e:
|
| 28 |
logging.error(f"Error: {str(e)}")
|
| 29 |
return jsonify({"error": str(e)}), 500
|
| 30 |
|
| 31 |
-
# Run locally (
|
| 32 |
if __name__ == "__main__":
|
| 33 |
port = int(os.environ.get("PORT", 7860))
|
| 34 |
app.run(host="0.0.0.0", port=port)
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import sample_rust
|
| 4 |
import os
|
|
|
|
| 12 |
|
| 13 |
@app.route("/")
|
| 14 |
def index():
|
| 15 |
+
return "Hello from Rust-Powered Flask!"
|
| 16 |
|
| 17 |
@app.route("/ask", methods=["POST"])
|
| 18 |
def ask():
|
| 19 |
try:
|
| 20 |
+
data = request.get_json(force=True)
|
| 21 |
question = data.get("question", "World")
|
| 22 |
|
| 23 |
logging.info(f"Received question: {question}")
|
| 24 |
+
result = sample_rust.hello(question) # ✅ Call Rust function
|
| 25 |
+
|
| 26 |
+
# ✅ Return properly formatted JSON response
|
| 27 |
+
return jsonify({
|
| 28 |
+
"question": question,
|
| 29 |
+
"answer": result
|
| 30 |
+
})
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
logging.error(f"Error: {str(e)}")
|
| 34 |
return jsonify({"error": str(e)}), 500
|
| 35 |
|
| 36 |
+
# Run locally (optional)
|
| 37 |
if __name__ == "__main__":
|
| 38 |
port = int(os.environ.get("PORT", 7860))
|
| 39 |
app.run(host="0.0.0.0", port=port)
|