Guilherme34
commited on
Commit
•
8fac83c
1
Parent(s):
fc4c647
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,37 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
import json
|
4 |
-
from io import BytesIO
|
5 |
-
|
6 |
-
from flask import Flask, jsonify, render_template, request, send_file
|
7 |
-
|
8 |
-
from modules.inference import infer_t5
|
9 |
-
from modules.dataset import query_emotion
|
10 |
-
|
11 |
-
# https://huggingface.co/settings/tokens
|
12 |
-
# https://huggingface.co/spaces/{username}/{space}/settings
|
13 |
-
API_TOKEN = os.getenv("BIG_GAN_TOKEN")
|
14 |
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
end = request.args.get("end")
|
50 |
-
|
51 |
-
print(start)
|
52 |
-
print(end)
|
53 |
-
|
54 |
-
output = query_emotion(int(start), int(end))
|
55 |
-
|
56 |
-
return jsonify({"output": output})
|
57 |
-
|
58 |
-
|
59 |
-
if __name__ == "__main__":
|
60 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from chat import generate_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
@app.route('/openai/v1/chat/completions', methods=['POST'])
|
7 |
+
def chat_completions():
|
8 |
+
data = request.get_json()
|
9 |
+
message = data['messages'][0]['content']
|
10 |
+
history = data.get('history', [])
|
11 |
+
|
12 |
+
response = generate_response(message, history)
|
13 |
+
|
14 |
+
return jsonify({
|
15 |
+
'id': 'chat_completion_id',
|
16 |
+
'object': 'chat.completion',
|
17 |
+
'created': 1234567890,
|
18 |
+
'model': 'Samanthav3-MIXTRALDOLPHIN-LORA',
|
19 |
+
'choices': [
|
20 |
+
{
|
21 |
+
'index': 0,
|
22 |
+
'message': {
|
23 |
+
'role': 'assistant',
|
24 |
+
'content': response
|
25 |
+
},
|
26 |
+
'finish_reason': 'stop'
|
27 |
+
}
|
28 |
+
],
|
29 |
+
'usage': {
|
30 |
+
'prompt_tokens': len(tokenizer.encode(message)),
|
31 |
+
'completion_tokens': len(tokenizer.encode(response)),
|
32 |
+
'total_tokens': len(tokenizer.encode(message)) + len(tokenizer.encode(response))
|
33 |
+
}
|
34 |
+
})
|
35 |
+
|
36 |
+
if __name__ == '__main__':
|
37 |
+
app.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|