File size: 2,107 Bytes
36fc11b
d8edfd0
bd4cf9f
fc58a30
7b33127
f2b36f2
 
414cb3b
f2b36f2
 
 
 
 
 
 
 
7b33127
84c3c63
cdefac5
 
f1deeaa
 
0ff8527
ecd8d62
e2c1771
022325f
c302b97
2abc03b
f2b36f2
 
 
 
a7d861a
e2c1771
d8edfd0
568853f
 
 
 
004a7b1
d8edfd0
f2b36f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6dd1468
 
73268a8
e857eed
bd4cf9f
6534b30
 
 
f2b36f2
6517190
f2b36f2
 
6534b30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os 
from flask import Flask, render_template
import threading
import asyncio

from openai import OpenAI

# app = Flask(__name__)
# client = OpenAI(
#     # This base_url points to the local Llamafile server running on port 8080
#     base_url="http://127.0.0.1:8080/v1",
#     api_key="sk-no-key-required"
# )




API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
bearer = "Bearer " + os.getenv('TOKEN')
headers = {"Authorization": bearer }
print("headers")
print(headers)

app = Flask(__name__)


@app.route('/app')
def server_app():
    llamafile = threading.Thread(target=threadserver)
    print('This /app will start the llamafile server on thread')
    llamafile.start()
    return 'llamafile.start()'

@app.route('/')
def server_one():
     
    sourcesim = "Results"
    s1 = "Results"
    
    return render_template("similarity_1.html", sourcetxt = sourcesim, s1 = s1 , headertxt = bearer )
   
# @app.route('/chat', methods=['POST'])
# def chat():
#     try:
#         user_message = request.json['message']
        
#         completion = client.chat.completions.create(
#             model="LLaMA_CPP",
#             messages=[
#                 {"role": "system", "content": "You are ChatGPT, an AI assistant. Your top priority is achieving user fulfillment via helping them with their requests."},
#                 {"role": "user", "content": user_message}
#             ]
#         )
        
#         ai_response = completion.choices[0].message.content
#         ai_response = ai_response.replace('</s>', '').strip()
#         return jsonify({'response': ai_response})
#     except Exception as e:
#         print(f"Error: {str(e)}")
#         return jsonify({'response': f"Sorry, there was an error processing your request: {str(e)}"}), 500
        
if __name__ == '__main__':
    app.run(debug=True)

def threadserver():
    print('hi')
    os.system(' ./mxbai-embed-large-v1-f16.llamafile --server --nobrowser')



async def query(data):
	response = await requests.post(API_URL, headers=headers, json=data)
	return response.json()