Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ logging.basicConfig(level=logging.DEBUG)
|
|
29 |
logger = logging.getLogger(__name__)
|
30 |
|
31 |
# Load model and tokenizer
|
32 |
-
model_name = "FreedomIntelligence/Apollo-
|
33 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
35 |
tokenizer.pad_token = tokenizer.eos_token
|
@@ -94,44 +94,42 @@ class TimeoutCallback(BaseCallbackHandler):
|
|
94 |
raise TimeoutError("LLM processing timeout")
|
95 |
|
96 |
|
97 |
-
|
98 |
-
# lang = detect(question)
|
99 |
-
# if lang == "ar":
|
100 |
-
# return (
|
101 |
-
# "أجب على السؤال الطبي التالي بلغة عربية فصحى، بإجابة دقيقة ومفصلة. إذا لم تجد معلومات كافية في السياق، استخدم معرفتك الطبية السابقة. \n"
|
102 |
-
# "- عدم تكرار أي نقطة أو عبارة أو كلمة\n"
|
103 |
-
# "- وضوح وسلاسة كل نقطة\n"
|
104 |
-
# "- تجنب الحشو والعبارات الزائدة\n"
|
105 |
-
# f"\nالسؤال: {question}\nالإجابة:"
|
106 |
-
# )
|
107 |
-
# else:
|
108 |
-
# return (
|
109 |
-
# "Answer the following medical question in clear English with a detailed, non-redundant response. "
|
110 |
-
# "Do not repeat ideas, phrases, or restate the question in the answer. If the context lacks relevant "
|
111 |
-
# "information, rely on your prior medical knowledge. If the answer involves multiple points, list them "
|
112 |
-
# "in concise and distinct bullet points:\n"
|
113 |
-
# f"Question: {question}\nAnswer:"
|
114 |
-
# )
|
115 |
-
|
116 |
-
from langdetect import detect
|
117 |
-
|
118 |
-
def generate_prompt(question):
|
119 |
lang = detect(question)
|
120 |
if lang == "ar":
|
121 |
-
return
|
122 |
-
|
123 |
-
- عدم تكرار أي نقطة أو عبارة أو
|
124 |
-
- وضوح وسلاسة كل
|
125 |
-
- تجنب الحشو والعبارات
|
126 |
-
|
127 |
-
|
128 |
-
الإجابة:
|
129 |
-
"""
|
130 |
-
|
131 |
else:
|
132 |
-
return
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
# === ROUTES === #
|
137 |
@app.get("/")
|
|
|
29 |
logger = logging.getLogger(__name__)
|
30 |
|
31 |
# Load model and tokenizer
|
32 |
+
model_name = "FreedomIntelligence/Apollo-7B"
|
33 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
34 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
35 |
tokenizer.pad_token = tokenizer.eos_token
|
|
|
94 |
raise TimeoutError("LLM processing timeout")
|
95 |
|
96 |
|
97 |
+
def generate_prompt(question: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
lang = detect(question)
|
99 |
if lang == "ar":
|
100 |
+
return (
|
101 |
+
"أجب على السؤال الطبي التالي بلغة عربية فصحى، بإجابة دقيقة ومفصلة. إذا لم تجد معلومات كافية في السياق، استخدم معرفتك الطبية السابقة. \n"
|
102 |
+
"- عدم تكرار أي نقطة أو عبارة أو كلمة\n"
|
103 |
+
"- وضوح وسلاسة كل نقطة\n"
|
104 |
+
"- تجنب الحشو والعبارات الزائدة\n"
|
105 |
+
f"\nالسؤال: {question}\nالإجابة:"
|
106 |
+
)
|
|
|
|
|
|
|
107 |
else:
|
108 |
+
return (
|
109 |
+
"Answer the following medical question in clear English with a detailed, non-redundant response. "
|
110 |
+
"Do not repeat ideas, phrases, or restate the question in the answer. If the context lacks relevant "
|
111 |
+
"information, rely on your prior medical knowledge. If the answer involves multiple points, list them "
|
112 |
+
"in concise and distinct bullet points:\n"
|
113 |
+
f"Question: {question}\nAnswer:"
|
114 |
+
)
|
115 |
+
|
116 |
+
# def generate_prompt(question):
|
117 |
+
# lang = detect(question)
|
118 |
+
# if lang == "ar":
|
119 |
+
# return f"""أجب على السؤال الطبي التالي بلغة عربية فصحى، بإجابة دقيقة ومفصلة. إذا لم تجد معلومات كافية في السياق، استخدم معرفتك الطبية السابقة.
|
120 |
+
# وتأكد من ان:
|
121 |
+
# - عدم تكرار أي نقطة أو عبارة أو كلمة
|
122 |
+
# - وضوح وسلاسة كل نقطة
|
123 |
+
# - تجنب الحشو والعبارات الزائدة-
|
124 |
+
|
125 |
+
# السؤال: {question}
|
126 |
+
# الإجابة:
|
127 |
+
# """
|
128 |
+
|
129 |
+
# else:
|
130 |
+
# return f"""Answer the following medical question in clear English with a detailed, non-redundant response. Do not repeat ideas, phrases, or restate the question in the answer. If the context lacks relevant information, rely on your prior medical knowledge. If the answer involves multiple points, list them in concise and distinct bullet points:
|
131 |
+
# Question: {question}
|
132 |
+
# Answer:"""
|
133 |
|
134 |
# === ROUTES === #
|
135 |
@app.get("/")
|