Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -10,53 +10,7 @@ app = Flask(__name__)
|
|
10 |
|
11 |
|
12 |
# Tracking API usage
|
13 |
-
|
14 |
-
'Mistral7B': 0,
|
15 |
-
'ChatGpt': 0,
|
16 |
-
'News': 0,
|
17 |
-
"Web": 0,
|
18 |
-
}
|
19 |
-
|
20 |
-
def Load():
|
21 |
-
global counter
|
22 |
-
current_datetime = datetime.now()
|
23 |
-
|
24 |
-
# Extract only the date
|
25 |
-
current_date = str(current_datetime.date())
|
26 |
-
file=listdir(r"static/data/")
|
27 |
-
if current_date in file:
|
28 |
-
with open(r"static/data/"+current_date,"r") as f:
|
29 |
-
counter=eval(f.read())
|
30 |
-
else:
|
31 |
-
counter={
|
32 |
-
'Mistral7B': 0,
|
33 |
-
'ChatGpt': 0,
|
34 |
-
'News': 0,
|
35 |
-
"Web": 0,
|
36 |
-
}
|
37 |
-
with open(r"static/data/"+current_date,"w") as f:
|
38 |
-
f.write(str(counter))
|
39 |
-
|
40 |
-
def Update():
|
41 |
-
# Get the current date and time
|
42 |
-
global counter
|
43 |
-
current_datetime = datetime.now()
|
44 |
-
|
45 |
-
# Extract only the date
|
46 |
-
current_date = str(current_datetime.date())
|
47 |
-
file=listdir(r"static/data/")
|
48 |
-
if current_date in file:
|
49 |
-
with open(r"static/data/"+current_date,"w") as f:
|
50 |
-
f.write(str(counter))
|
51 |
-
else:
|
52 |
-
counter={
|
53 |
-
'Mistral7B': 0,
|
54 |
-
'ChatGpt': 0,
|
55 |
-
'News': 0,
|
56 |
-
"Web": 0,
|
57 |
-
}
|
58 |
-
with open(r"static/data/"+current_date,"w") as f:
|
59 |
-
f.write(str(counter))
|
60 |
|
61 |
@app.route('/mistral7b', methods=['POST'])
|
62 |
def generate():
|
@@ -76,8 +30,6 @@ def generate():
|
|
76 |
'messages': updated_messages,
|
77 |
'execution_time': execution_time
|
78 |
}
|
79 |
-
counter['Mistral7B']+=1
|
80 |
-
Update()
|
81 |
return jsonify(result)
|
82 |
|
83 |
@app.route('/chatgpt', methods=['POST'])
|
@@ -97,8 +49,6 @@ def chat():
|
|
97 |
'messages': updated_messages,
|
98 |
'execution_time': execution_time
|
99 |
}
|
100 |
-
counter["ChatGpt"]+=1
|
101 |
-
Update()
|
102 |
return jsonify(result)
|
103 |
|
104 |
@app.route('/news', methods=['GET'])
|
@@ -117,8 +67,6 @@ def get_news():
|
|
117 |
'error': error,
|
118 |
'execution_time': execution_time
|
119 |
}
|
120 |
-
counter["News"]+=1
|
121 |
-
Update()
|
122 |
return jsonify(result)
|
123 |
|
124 |
@app.route('/web', methods=['GET'])
|
@@ -136,7 +84,6 @@ def get_counters():
|
|
136 |
global counter
|
137 |
return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))})
|
138 |
|
139 |
-
Load()
|
140 |
|
141 |
if __name__ == '__main__':
|
142 |
app.run()
|
|
|
10 |
|
11 |
|
12 |
# Tracking API usage
|
13 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
@app.route('/mistral7b', methods=['POST'])
|
16 |
def generate():
|
|
|
30 |
'messages': updated_messages,
|
31 |
'execution_time': execution_time
|
32 |
}
|
|
|
|
|
33 |
return jsonify(result)
|
34 |
|
35 |
@app.route('/chatgpt', methods=['POST'])
|
|
|
49 |
'messages': updated_messages,
|
50 |
'execution_time': execution_time
|
51 |
}
|
|
|
|
|
52 |
return jsonify(result)
|
53 |
|
54 |
@app.route('/news', methods=['GET'])
|
|
|
67 |
'error': error,
|
68 |
'execution_time': execution_time
|
69 |
}
|
|
|
|
|
70 |
return jsonify(result)
|
71 |
|
72 |
@app.route('/web', methods=['GET'])
|
|
|
84 |
global counter
|
85 |
return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))})
|
86 |
|
|
|
87 |
|
88 |
if __name__ == '__main__':
|
89 |
app.run()
|