Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,10 @@
|
|
1 |
-
import
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
5 |
|
6 |
-
def respond(
|
7 |
-
message,
|
8 |
-
history: list[tuple[str, str]],
|
9 |
-
system_message,
|
10 |
-
max_tokens,
|
11 |
-
temperature,
|
12 |
-
top_p,
|
13 |
-
):
|
14 |
messages = [{"role": "system", "content": system_message}]
|
15 |
|
16 |
for val in history:
|
@@ -20,7 +14,6 @@ def respond(
|
|
20 |
messages.append({"role": "assistant", "content": val[1]})
|
21 |
|
22 |
messages.append({"role": "user", "content": message})
|
23 |
-
|
24 |
response = ""
|
25 |
|
26 |
for message in client.chat_completion(
|
@@ -32,23 +25,25 @@ def respond(
|
|
32 |
):
|
33 |
token = message.choices[0].delta.content
|
34 |
response += token
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
)
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
app = Flask(__name__)
|
5 |
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
6 |
|
7 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
messages = [{"role": "system", "content": system_message}]
|
9 |
|
10 |
for val in history:
|
|
|
14 |
messages.append({"role": "assistant", "content": val[1]})
|
15 |
|
16 |
messages.append({"role": "user", "content": message})
|
|
|
17 |
response = ""
|
18 |
|
19 |
for message in client.chat_completion(
|
|
|
25 |
):
|
26 |
token = message.choices[0].delta.content
|
27 |
response += token
|
28 |
+
return response
|
29 |
+
|
30 |
+
@app.route('/')
|
31 |
+
def index():
|
32 |
+
return render_template('index.html')
|
33 |
+
|
34 |
+
@app.route('/get_response', methods=['POST'])
|
35 |
+
def get_response():
|
36 |
+
data = request.json
|
37 |
+
message = data['message']
|
38 |
+
history = data.get('history', [])
|
39 |
+
system_message = data.get('system_message', "You are a friendly chatbot.")
|
40 |
+
max_tokens = int(data.get('max_tokens', 512))
|
41 |
+
temperature = float(data.get('temperature', 0.7))
|
42 |
+
top_p = float(data.get('top_p', 0.95))
|
43 |
+
|
44 |
+
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
45 |
+
return jsonify({'response': response})
|
46 |
+
|
47 |
+
if __name__ == '__main__':
|
48 |
+
app.run(debug=True)
|
49 |
+
|