Spaces:
Build error
Build error
Merge branch 'main' of https://huggingface.co/spaces/Mohamed284/AskNature_BioChat
Browse files
.gitattributes
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
bm25_index.pkl_5c0c37d3cbc20e235eeec7cffd2d312f filter=lfs diff=lfs merge=lfs -text
|
| 2 |
documents_v1_5c0c37d3cbc20e235eeec7cffd2d312f.pkl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 1 |
bm25_index.pkl_5c0c37d3cbc20e235eeec7cffd2d312f filter=lfs diff=lfs merge=lfs -text
|
| 2 |
documents_v1_5c0c37d3cbc20e235eeec7cffd2d312f.pkl filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
faiss_index_5c0c37d3cbc20e235eeec7cffd2d312f/index.faiss filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
faiss_index_5c0c37d3cbc20e235eeec7cffd2d312f/index.pkl filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -21,7 +21,7 @@ from collections import defaultdict
|
|
| 21 |
import hashlib
|
| 22 |
from tqdm import tqdm
|
| 23 |
from dotenv import load_dotenv
|
| 24 |
-
|
| 25 |
load_dotenv()
|
| 26 |
|
| 27 |
# --- Configuration ---
|
|
@@ -216,17 +216,19 @@ class EnhancedRetriever:
|
|
| 216 |
|
| 217 |
# --- Generation System ---
|
| 218 |
SYSTEM_PROMPT = """
|
| 219 |
-
**Biomimicry
|
| 220 |
|
| 221 |
-
-
|
| 222 |
-
-
|
| 223 |
-
-
|
| 224 |
-
-
|
| 225 |
-
-
|
|
|
|
| 226 |
|
| 227 |
Context: {context}
|
| 228 |
"""
|
| 229 |
|
|
|
|
| 230 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=20))
|
| 231 |
def get_ai_response(query: str, context: str, model: str) -> str:
|
| 232 |
result = "" # Initialize the result variable
|
|
@@ -314,7 +316,15 @@ def generate_response(question: str, model: str) -> str:
|
|
| 314 |
return "An error occurred processing your request."
|
| 315 |
|
| 316 |
# --- Gradio Interface ---
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
response = generate_response(question, model)
|
| 319 |
return "", history + [(question, response)]
|
| 320 |
|
|
@@ -324,7 +334,7 @@ with gr.Blocks(title="AskNature BioRAG Expert", theme=gr.themes.Soft()) as demo:
|
|
| 324 |
chatbot = gr.Chatbot(label="Dialogue History", height=500)
|
| 325 |
with gr.Row():
|
| 326 |
question = gr.Textbox(placeholder="Ask about biomimicry (e.g. 'How does Werewool use coral proteins to make fibers?')", label="Inquiry", scale=4)
|
| 327 |
-
model_selector = gr.Dropdown(choices=
|
| 328 |
clear_btn = gr.Button("Clear History", variant="secondary")
|
| 329 |
|
| 330 |
gr.Markdown("""
|
|
|
|
| 21 |
import hashlib
|
| 22 |
from tqdm import tqdm
|
| 23 |
from dotenv import load_dotenv
|
| 24 |
+
import pickle
|
| 25 |
load_dotenv()
|
| 26 |
|
| 27 |
# --- Configuration ---
|
|
|
|
| 216 |
|
| 217 |
# --- Generation System ---
|
| 218 |
SYSTEM_PROMPT = """
|
| 219 |
+
**Expert Biomimicry Advisor**
|
| 220 |
|
| 221 |
+
- **Objective**: Your role is to provide expert-level insights on biomimicry by using the provided AskNature context. When context is unavailable, rely on general knowledge.
|
| 222 |
+
- **Answer Precision**: Always use precise technical language and structure your response logically, emphasizing the relationship between biological concepts and innovation.
|
| 223 |
+
- **References**: Use numeric citations (e.g., [1]) when referencing data points or studies, corresponding to the URLs or sources provided in the context.
|
| 224 |
+
- **Content Formatting**: Bold technical terms for emphasis (e.g., **protein synthesis**, **ecosystem mimicry**).
|
| 225 |
+
- **Conclusion**: Summarize the sustainability impacts of the discussed technologies or ideas. Highlight innovative aspects and benefits.
|
| 226 |
+
- **References Section**: At the end of your response, list all cited sources with their corresponding numbers.
|
| 227 |
|
| 228 |
Context: {context}
|
| 229 |
"""
|
| 230 |
|
| 231 |
+
|
| 232 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=20))
|
| 233 |
def get_ai_response(query: str, context: str, model: str) -> str:
|
| 234 |
result = "" # Initialize the result variable
|
|
|
|
| 316 |
return "An error occurred processing your request."
|
| 317 |
|
| 318 |
# --- Gradio Interface ---
|
| 319 |
+
# Define the mapping from display names to actual model identifiers
|
| 320 |
+
model_mapping = {
|
| 321 |
+
"Gemini-2.0-Flash": "gemini-2.0-flash",
|
| 322 |
+
"Meta-llama-3-70b-instruct(GWDG)": "meta-llama-3-70b-instruct",
|
| 323 |
+
"llama3-70b-8192(Groq)": "llama3-70b-8192"
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
def chat_interface(question: str, history: List[Tuple[str, str]], display_model: str):
|
| 327 |
+
model = model_mapping.get(display_model, "gemini-2.0-flash") # Default to Gemini if not found
|
| 328 |
response = generate_response(question, model)
|
| 329 |
return "", history + [(question, response)]
|
| 330 |
|
|
|
|
| 334 |
chatbot = gr.Chatbot(label="Dialogue History", height=500)
|
| 335 |
with gr.Row():
|
| 336 |
question = gr.Textbox(placeholder="Ask about biomimicry (e.g. 'How does Werewool use coral proteins to make fibers?')", label="Inquiry", scale=4)
|
| 337 |
+
model_selector = gr.Dropdown(choices=list(model_mapping.keys()), label="Generation Model", value="Gemini-2.0-Flash")
|
| 338 |
clear_btn = gr.Button("Clear History", variant="secondary")
|
| 339 |
|
| 340 |
gr.Markdown("""
|
faiss_index_5c0c37d3cbc20e235eeec7cffd2d312f/index.faiss
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11552dd7976f09d84b9265d14029a38d1bd860e923d4d1ac45c35ebaa0a5f587
|
| 3 |
+
size 92651565
|
faiss_index_5c0c37d3cbc20e235eeec7cffd2d312f/index.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3c8fdbcc5225fac384af24db78eb64f31042147613cb40809c257fdaa46c0c01
|
| 3 |
+
size 6657792
|