Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,6 +36,16 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
| 36 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 37 |
tokenizer.pad_token = tokenizer.eos_token
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
# Generation settings
|
| 40 |
generation_config = GenerationConfig(
|
| 41 |
max_new_tokens=150,
|
|
@@ -56,16 +66,6 @@ llm_pipeline = pipeline(
|
|
| 56 |
)
|
| 57 |
llm = HuggingFacePipeline(pipeline=llm_pipeline)
|
| 58 |
|
| 59 |
-
# Connect to Qdrant + embedding
|
| 60 |
-
embedding = HuggingFaceEmbeddings(model_name="Omartificial-Intelligence-Space/GATE-AraBert-v1")
|
| 61 |
-
qdrant_client = QdrantClient(url=QDRANT_URL, api_key=QDRANT_API_KEY)
|
| 62 |
-
|
| 63 |
-
vector_store = Qdrant(
|
| 64 |
-
client=qdrant_client,
|
| 65 |
-
collection_name=COLLECTION_NAME,
|
| 66 |
-
embeddings=embedding
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
retriever = vector_store.as_retriever(search_kwargs={"k": 3})
|
| 70 |
|
| 71 |
# Set up RAG QA chain
|
|
@@ -110,6 +110,26 @@ def generate_prompt(question: str) -> str:
|
|
| 110 |
Question: {question}
|
| 111 |
Answer:"""
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# Input schema
|
| 114 |
# class ChatRequest(BaseModel):
|
| 115 |
# message: str
|
|
|
|
| 36 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 37 |
tokenizer.pad_token = tokenizer.eos_token
|
| 38 |
|
| 39 |
+
# Connect to Qdrant + embedding
|
| 40 |
+
embedding = HuggingFaceEmbeddings(model_name="Omartificial-Intelligence-Space/GATE-AraBert-v1")
|
| 41 |
+
qdrant_client = QdrantClient(url=QDRANT_URL, api_key=QDRANT_API_KEY)
|
| 42 |
+
|
| 43 |
+
vector_store = Qdrant(
|
| 44 |
+
client=qdrant_client,
|
| 45 |
+
collection_name=COLLECTION_NAME,
|
| 46 |
+
embeddings=embedding
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
# Generation settings
|
| 50 |
generation_config = GenerationConfig(
|
| 51 |
max_new_tokens=150,
|
|
|
|
| 66 |
)
|
| 67 |
llm = HuggingFacePipeline(pipeline=llm_pipeline)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
retriever = vector_store.as_retriever(search_kwargs={"k": 3})
|
| 70 |
|
| 71 |
# Set up RAG QA chain
|
|
|
|
| 110 |
Question: {question}
|
| 111 |
Answer:"""
|
| 112 |
|
| 113 |
+
|
| 114 |
+
# def generate_prompt(question: str) -> str:
|
| 115 |
+
# lang = detect(question)
|
| 116 |
+
# if lang == "ar":
|
| 117 |
+
# return (
|
| 118 |
+
# "أجب على السؤال الطبي التالي بلغة عربية فصحى، بإجابة دقيقة ومفصلة. إذا لم تجد معلومات كافية في السياق، استخدم معرفتك الطبية السابقة. \n"
|
| 119 |
+
# "- عدم تكرار أي نقطة أو عبارة أو كلمة\n"
|
| 120 |
+
# "- وضوح وسلاسة كل نقطة\n"
|
| 121 |
+
# "- تجنب الحشو والعبارات الزائدة\n"
|
| 122 |
+
# f"\nالسؤال: {question}\nالإجابة:"
|
| 123 |
+
# )
|
| 124 |
+
# else:
|
| 125 |
+
# return (
|
| 126 |
+
# "Answer the following medical question in clear English with a detailed, non-redundant response. "
|
| 127 |
+
# "Do not repeat ideas, phrases, or restate the question in the answer. If the context lacks relevant "
|
| 128 |
+
# "information, rely on your prior medical knowledge. If the answer involves multiple points, list them "
|
| 129 |
+
# "in concise and distinct bullet points:\n"
|
| 130 |
+
# f"Question: {question}\nAnswer:"
|
| 131 |
+
# )
|
| 132 |
+
|
| 133 |
# Input schema
|
| 134 |
# class ChatRequest(BaseModel):
|
| 135 |
# message: str
|