Futuresony commited on
Commit
fbd9c6a
·
verified ·
1 Parent(s): b7453ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -35
app.py CHANGED
@@ -10,42 +10,24 @@ client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
10
 
11
  @app.route("/")
12
  def home():
13
- return HTML_TEMPLATE
14
-
15
- function fetchMessageFromAI(message) {
16
- document.getElementById('typing-indicator').style.display = 'flex';
17
-
18
- fetch('/message', {
19
- method: 'POST',
20
- headers: {
21
- 'Content-Type': 'application/json',
22
- },
23
- body: JSON.stringify({ text: message })
24
- })
25
- .then(response => {
26
- if (!response.ok) {
27
- throw new Error(`Server error: ${response.statusText}`);
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)