Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,40 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
import
|
3 |
-
import base64
|
4 |
-
import requests
|
5 |
-
app = Flask(__name__)
|
6 |
-
|
7 |
-
# GitHub credentials
|
8 |
-
GITHUB_TOKEN = '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' # Set your token in environment variables
|
9 |
-
REPO_OWNER = 'hussein2000-oo'
|
10 |
-
REPO_NAME = 'dbailloolloloolollhrthlnewrgnk'
|
11 |
-
USER_FILE_NAME = 'user.json'
|
12 |
-
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
user_data = json.loads(base64.b64decode(content['content']).decode('utf-8'))
|
23 |
-
return user_data
|
24 |
-
else:
|
25 |
-
return None # Return None if fetching fails
|
26 |
-
|
27 |
-
|
28 |
-
@app.route('/get_security_questions', methods=['POST'])
|
29 |
-
def get_security_questions():
|
30 |
-
data = request.json
|
31 |
-
username = data.get('username')
|
32 |
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
-
if
|
36 |
-
|
37 |
-
return jsonify({"
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
if __name__ == '__main__':
|
43 |
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Initialize the InferenceClient with your API key
|
5 |
+
x="hf_uYlR"
|
6 |
+
y="EMsDNbxQPJCSAHgwthrylHZZKKmGyg"
|
7 |
+
u=x+y
|
8 |
+
client = InferenceClient(api_key=f"{u}")
|
9 |
|
10 |
+
# Create a Flask app
|
11 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
@app.route('/chat', methods=['POST'])
|
14 |
+
def chat():
|
15 |
+
# Get user message from the request
|
16 |
+
user_message = request.json.get('message')
|
17 |
|
18 |
+
# Check if the user message is provided
|
19 |
+
if not user_message:
|
20 |
+
return jsonify({"error": "No message provided"}), 400
|
21 |
+
|
22 |
+
# Create a single message list for the request
|
23 |
+
messages = [{"role": "user", "content": user_message}]
|
24 |
+
|
25 |
+
# Create the chat completion request with the current message
|
26 |
+
response = client.chat.completions.create(
|
27 |
+
model="Qwen/Qwen2.5-72B-Instruct",
|
28 |
+
messages=messages,
|
29 |
+
max_tokens=1024,
|
30 |
+
stream=False # Set stream to False to get the full response at once
|
31 |
+
)
|
32 |
+
|
33 |
+
# Get the assistant's response
|
34 |
+
assistant_message = response.choices[0].message.content
|
35 |
+
|
36 |
+
# Return the assistant's response as JSON
|
37 |
+
return jsonify({"response": assistant_message})
|
38 |
|
39 |
if __name__ == '__main__':
|
40 |
app.run(host="0.0.0.0", port=7860)
|