Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,42 +10,24 @@ client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
|
| 10 |
|
| 11 |
@app.route("/")
|
| 12 |
def home():
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
}
|
| 29 |
-
return response.json();
|
| 30 |
-
})
|
| 31 |
-
.then(data => {
|
| 32 |
-
document.getElementById('typing-indicator').style.display = 'none';
|
| 33 |
-
|
| 34 |
-
if (data.response) {
|
| 35 |
-
addAIResponse(data.response, message);
|
| 36 |
-
} else {
|
| 37 |
-
console.error("No response from the server.");
|
| 38 |
-
}
|
| 39 |
-
})
|
| 40 |
-
.catch(error => {
|
| 41 |
-
document.getElementById('typing-indicator').style.display = 'none';
|
| 42 |
-
console.error('Error:', error);
|
| 43 |
-
appendMessage("An error occurred. Please try again later.", 'ai');
|
| 44 |
-
});
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
# Use PORT environment variable or default to 7860
|
| 50 |
port = int(os.getenv("PORT", 7860))
|
| 51 |
-
app.run(host="0.0.0.0", port=port)
|
|
|
|
| 10 |
|
| 11 |
@app.route("/")
|
| 12 |
def home():
|
| 13 |
+
# Render the HTML template
|
| 14 |
+
return render_template("index.html")
|
| 15 |
+
|
| 16 |
+
@app.route("/message", methods=["POST"])
|
| 17 |
+
def fetch_message():
|
| 18 |
+
data = request.json
|
| 19 |
+
message = data.get("text", "")
|
| 20 |
+
if not message:
|
| 21 |
+
return jsonify({"error": "No input provided."}), 400
|
| 22 |
+
|
| 23 |
+
# Process the message using the Hugging Face model
|
| 24 |
+
try:
|
| 25 |
+
response = client.text_generation(message)
|
| 26 |
+
return jsonify({"response": response})
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
# Use PORT environment variable or default to 7860
|
| 32 |
port = int(os.getenv("PORT", 7860))
|
| 33 |
+
app.run(host="0.0.0.0", port=port)
|