Spaces:
Build error
Build error
Commit ·
f9ef51a
1
Parent(s): c9dbeb3
add counter limit
Browse files- src/app.py +5 -2
- src/handler.py +17 -0
src/app.py
CHANGED
|
@@ -16,7 +16,7 @@ from streamlit_option_menu import option_menu
|
|
| 16 |
import os
|
| 17 |
import re
|
| 18 |
from model import ask
|
| 19 |
-
from handler import save_feedback, translate_answer, check_question_feedback, translate_text, is_overlimit
|
| 20 |
from text import feedback_instr, no_affiliation, description, no_replacement_for_official_advice, source_of_answer_short, source_of_answer
|
| 21 |
from langdetect import detect
|
| 22 |
from deep_translator import GoogleTranslator
|
|
@@ -197,7 +197,10 @@ if selected == "Chatbot":
|
|
| 197 |
"content": "Hello! I'm Instant. How can I help you today?"
|
| 198 |
}]
|
| 199 |
|
| 200 |
-
is_limit_exceeded =
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
working_hours = (10 <= current_hour < 13) or (17 <= current_hour < 20)
|
| 203 |
if working_hours and not is_limit_exceeded:
|
|
|
|
| 16 |
import os
|
| 17 |
import re
|
| 18 |
from model import ask
|
| 19 |
+
from handler import save_feedback, translate_answer, check_question_feedback, translate_text, is_overlimit, refresh_web_counter
|
| 20 |
from text import feedback_instr, no_affiliation, description, no_replacement_for_official_advice, source_of_answer_short, source_of_answer
|
| 21 |
from langdetect import detect
|
| 22 |
from deep_translator import GoogleTranslator
|
|
|
|
| 197 |
"content": "Hello! I'm Instant. How can I help you today?"
|
| 198 |
}]
|
| 199 |
|
| 200 |
+
is_limit_exceeded = False
|
| 201 |
+
refresh = refresh_web_counter()
|
| 202 |
+
if refresh:
|
| 203 |
+
is_limit_exceeded = is_overlimit()
|
| 204 |
|
| 205 |
working_hours = (10 <= current_hour < 13) or (17 <= current_hour < 20)
|
| 206 |
if working_hours and not is_limit_exceeded:
|
src/handler.py
CHANGED
|
@@ -145,6 +145,23 @@ def add_question_ticker():
|
|
| 145 |
print("Error updating web counter:", e)
|
| 146 |
return False
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
def is_overlimit():
|
| 149 |
try:
|
| 150 |
counter = web_counter_collection.find_one({"type": "web"})
|
|
|
|
| 145 |
print("Error updating web counter:", e)
|
| 146 |
return False
|
| 147 |
|
| 148 |
+
def refresh_web_counter():
|
| 149 |
+
current_hour = datetime.now().hour
|
| 150 |
+
refresh_hour = current_hour == 1
|
| 151 |
+
|
| 152 |
+
if refresh_hour:
|
| 153 |
+
try:
|
| 154 |
+
web_counter_collection.update_one(
|
| 155 |
+
{"type": "web"},
|
| 156 |
+
{
|
| 157 |
+
"$set": {"counter": 0, "timestamp": datetime.now(timezone.utc)}
|
| 158 |
+
}
|
| 159 |
+
)
|
| 160 |
+
except Exception as e:
|
| 161 |
+
print("Error refreshing web counter:", e)
|
| 162 |
+
|
| 163 |
+
return True
|
| 164 |
+
|
| 165 |
def is_overlimit():
|
| 166 |
try:
|
| 167 |
counter = web_counter_collection.find_one({"type": "web"})
|