Spaces:
Runtime error
Runtime error
| from flask import Flask, request, jsonify, render_template | |
| from huggingface_hub import InferenceClient | |
| import os | |
| # Initialize the Flask app | |
| app = Flask(__name__) | |
| # Initialize the Hugging Face Inference Client | |
| client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf") | |
| def home(): | |
| return HTML_TEMPLATE | |
| function fetchMessageFromAI(message) { | |
| document.getElementById('typing-indicator').style.display = 'flex'; | |
| fetch('/message', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ text: message }) | |
| }) | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error(`Server error: ${response.statusText}`); | |
| } | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| document.getElementById('typing-indicator').style.display = 'none'; | |
| if (data.response) { | |
| addAIResponse(data.response, message); | |
| } else { | |
| console.error("No response from the server."); | |
| } | |
| }) | |
| .catch(error => { | |
| document.getElementById('typing-indicator').style.display = 'none'; | |
| console.error('Error:', error); | |
| appendMessage("An error occurred. Please try again later.", 'ai'); | |
| }); | |
| } | |
| if __name__ == "__main__": | |
| # Use PORT environment variable or default to 7860 | |
| port = int(os.getenv("PORT", 7860)) | |
| app.run(host="0.0.0.0", port=port) |