Mohamed284 commited on
Commit
3d45da6
·
1 Parent(s): 70473b4
Files changed (3) hide show
  1. app.py +0 -1
  2. main.ipynb +90 -31
  3. requirements.txt +1 -1
app.py CHANGED
@@ -327,7 +327,6 @@ def chat_interface(question: str, history: List[Tuple[str, str]], display_model:
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
-
331
  with gr.Blocks(title="AskNature BioRAG Expert", theme=gr.themes.Soft()) as demo:
332
  gr.Markdown("# 🌿 AskNature RAG-based Chatbot")
333
  with gr.Row():
 
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
  with gr.Blocks(title="AskNature BioRAG Expert", theme=gr.themes.Soft()) as demo:
331
  gr.Markdown("# 🌿 AskNature RAG-based Chatbot")
332
  with gr.Row():
main.ipynb CHANGED
@@ -1194,6 +1194,8 @@
1194
  "INFO:__main__:Loading cached documents\n",
1195
  "INFO:__main__:Loading cached BM25 index\n",
1196
  "INFO:__main__:Loading cached FAISS index\n",
 
 
1197
  "c:\\Users\\Mohamed Elsafty\\.conda\\envs\\rag\\Lib\\site-packages\\gradio\\components\\chatbot.py:273: UserWarning: You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.\n",
1198
  " warnings.warn(\n"
1199
  ]
@@ -1202,15 +1204,15 @@
1202
  "name": "stdout",
1203
  "output_type": "stream",
1204
  "text": [
1205
- "* Running on local URL: http://127.0.0.1:7861\n"
1206
  ]
1207
  },
1208
  {
1209
  "name": "stderr",
1210
  "output_type": "stream",
1211
  "text": [
1212
- "INFO:httpx:HTTP Request: GET http://127.0.0.1:7861/gradio_api/startup-events \"HTTP/1.1 200 OK\"\n",
1213
- "INFO:httpx:HTTP Request: HEAD http://127.0.0.1:7861/ \"HTTP/1.1 200 OK\"\n"
1214
  ]
1215
  },
1216
  {
@@ -1224,7 +1226,7 @@
1224
  {
1225
  "data": {
1226
  "text/html": [
1227
- "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
1228
  ],
1229
  "text/plain": [
1230
  "<IPython.core.display.HTML object>"
@@ -1240,30 +1242,64 @@
1240
  "INFO:httpx:HTTP Request: GET https://api.gradio.app/pkg-version \"HTTP/1.1 200 OK\"\n",
1241
  "INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
1242
  "Embedding Progress: 0%| | 0/1 [00:00<?, ?it/s]INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/embeddings \"HTTP/1.1 200 OK\"\n",
1243
- "Embedding Progress: 100%|██████████| 1/1 [00:00<00:00, 6.02it/s]\n",
1244
- "INFO:__main__:Response from gemini-2.0-flash: Inspired by the **protein-based pigmentation** found in *Discosoma* coral, Werewool is developing biodegradable fibers for the textile industry [1]. This innovation utilizes **DNA-level fiber design** and **biotechnology** to create sustainable textiles with inherent color and other properties, eliminating the need for toxic dyes and petroleum-based synthetics [1]. The *Discosoma* coral's **red fluorescent protein (RFP)** serves as a model for creating color within the fiber itself [1].\n",
1245
  "\n",
1246
- "Furthermore, corals utilize **coral acid-rich proteins (CARP)** to build their rock-hard reefs [2]. These proteins interact with minerals like calcium carbonate, shaping them into **aragonite** crystals [2]. The corals then combine these crystals with other organic molecules, acting as cement to form the strong coral skeletons [2]. This **protein-mineral interaction**, along with the **molecular scaffolding** provided by proteins such as **collagen-based structure**, inspires the creation of durable materials [2].\n",
1247
  "\n",
1248
- "These approaches reduce the textile industry's reliance on harmful chemicals and unsustainable materials [1]. The global textile market produces 1.2 billion tons of CO2 equivalent per year and uses dyes that are responsible for 20% of global wastewater. The industry also depends on petroleum based synthetic fibers that account for 35% of global microplastic pollution [1].\n",
1249
  "\n",
1250
- "References:\n",
1251
- "[1] https://asknature.org/innovation/colorful-fibers-inspired-by-proteins-found-in-discosoma-coral/\n",
1252
- "[2] https://asknature.org/strategy/how-proteins-help-corals-build-rock-hard-reefs/\n",
1253
  "\n",
1254
- "INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
1255
- "INFO:__main__:Response from meta-llama-3-70b-instruct: ChatCompletion(id='chat-2b0d6684e9744a0ba5c48bad6bcdd4d7', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"**Coral Proteins: A Sustainable Solution for Eco-Friendly Fabrics**\\n\\nThe Discosoma coral's protein, specifically the red fluorescent protein (RFP), has inspired a revolutionary approach to creating eco-friendly fabrics without the need for toxic dyes. This innovation leverages the principles of **protein-based pigmentation** and **DNA-level fiber design** to produce biodegradable fibers with inherent color properties.\\n\\n**The Science Behind Coral Proteins**\\n\\nThe RFP found in Discosoma coral is a naturally occurring protein that provides the coral with its vibrant color. This protein is capable of absorbing light and emitting it at a longer wavelength, resulting in a red fluorescent color. By harnessing the properties of this protein, researchers can create fibers that exhibit similar color characteristics without the need for synthetic dyes.\\n\\n**How Coral Proteins Are Used in Fabric Production**\\n\\nTo create eco-friendly fabrics, researchers use biotechnology to design fibers at the DNA level. This involves identifying the protein structures found in nature, such as the RFP, and incorporating them into the fiber production process. The resulting fibers are reliant on these proteins for their color properties, eliminating the need for toxic dyes and finishes.\\n\\n**The Benefits of Coral Protein-Based Fabrics**\\n\\nThe use of coral proteins in fabric production offers several sustainability benefits, including:\\n\\n1. **Reduced environmental impact**: By eliminating the need for synthetic dyes and finishes, coral protein-based fabrics reduce the amount of toxic chemicals released into the environment.\\n2. **Biodegradable**: The fibers produced using coral proteins are biodegradable, reducing the amount of microplastic pollution in the environment.\\n3. **Sustainable production**: The use of biotechnology and natural proteins reduces the reliance on non-renewable resources and minimizes the carbon footprint of fabric production.\\n\\n**Conclusion**\\n\\nThe use of coral proteins in fabric production represents a significant step towards creating eco-friendly and sustainable textiles. By harnessing the power of nature and leveraging the principles of protein-based pigmentation and DNA-level fiber design, researchers can create biodegradable fibers with inherent color properties, reducing the environmental impact of the textile industry.\\n\\nReferences:\\n[1] https://asknature.org/innovation/colorful-fibers-inspired-by-proteins-found-in-discosoma-coral/\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=[]), stop_reason=None)], created=1739018886, model='meta-llama-3.1-70b-instruct', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=459, prompt_tokens=1341, total_tokens=1800, completion_tokens_details=None, prompt_tokens_details=None), prompt_logprobs=None)\n",
1256
- "INFO:__main__:Groq API Response: {'id': 'chatcmpl-55dc0b3b-1528-416e-bd30-93b4a851484e', 'object': 'chat.completion', 'created': 1739018907, 'model': 'llama3-70b-8192', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': \"Coral proteins are not directly involved in the production of eco-friendly fabrics without dyes. However, coral-inspired technologies have led to the development of innovative textile production methods that reduce the need for synthetic dyes.\\n\\nHere's how it works:\\n\\n1. **Biomimicry**: Scientists have taken inspiration from the vibrant colors and unique properties of coral reefs to develop sustainable textile production methods. Coral reefs are known for their incredible ability to display a range of colors without using pigments, instead relying on the structure of their skeletons to refract and scatter light.\\n2. **Structural coloration**: Researchers have replicated this natural phenomenon by developing fibers with nanostructured surfaces that create color through the manipulation of light. This approach, known as structural coloration, eliminates the need for synthetic dyes and pigments.\\n3. **Protein-based fibers**: Some companies are using protein-based fibers, such as those derived from silk, soy, or milk, to create sustainable textiles. These fibers can be engineered to have specific properties, such as structural coloration, that reduce the need for dyes.\\n4. **Natural coloration**: Other innovations involve using natural colorants, such as plant-based dyes, to create a more sustainable textile production process. These natural colorants can be derived from various sources, including fruits, vegetables, and spices.\\n\\nWhile coral proteins are not directly involved in this process, the biomimicry approach inspired by coral reefs has led to the development of innovative, eco-friendly textile production methods that reduce the need for synthetic dyes. These sustainable textiles have the potential to minimize environmental impacts, such as water pollution and energy consumption, associated with traditional dyeing processes.\"}, 'logprobs': None, 'finish_reason': 'stop'}], 'usage': {'queue_time': 0.016959538, 'prompt_tokens': 23, 'prompt_time': 0.004020428, 'completion_tokens': 339, 'completion_time': 1.021682599, 'total_tokens': 362, 'total_time': 1.025703027}, 'system_fingerprint': 'fp_753a4aecf6', 'x_groq': {'id': 'req_01jkjsnbgpf5n9ybppv09d1rb5'}}\n",
1257
- "INFO:__main__:Response from llama3-70b-8192: Coral proteins are not directly involved in the production of eco-friendly fabrics without dyes. However, coral-inspired technologies have led to the development of innovative textile production methods that reduce the need for synthetic dyes.\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258
  "\n",
1259
- "Here's how it works:\n",
1260
  "\n",
1261
- "1. **Biomimicry**: Scientists have taken inspiration from the vibrant colors and unique properties of coral reefs to develop sustainable textile production methods. Coral reefs are known for their incredible ability to display a range of colors without using pigments, instead relying on the structure of their skeletons to refract and scatter light.\n",
1262
- "2. **Structural coloration**: Researchers have replicated this natural phenomenon by developing fibers with nanostructured surfaces that create color through the manipulation of light. This approach, known as structural coloration, eliminates the need for synthetic dyes and pigments.\n",
1263
- "3. **Protein-based fibers**: Some companies are using protein-based fibers, such as those derived from silk, soy, or milk, to create sustainable textiles. These fibers can be engineered to have specific properties, such as structural coloration, that reduce the need for dyes.\n",
1264
- "4. **Natural coloration**: Other innovations involve using natural colorants, such as plant-based dyes, to create a more sustainable textile production process. These natural colorants can be derived from various sources, including fruits, vegetables, and spices.\n",
1265
  "\n",
1266
- "While coral proteins are not directly involved in this process, the biomimicry approach inspired by coral reefs has led to the development of innovative, eco-friendly textile production methods that reduce the need for synthetic dyes. These sustainable textiles have the potential to minimize environmental impacts, such as water pollution and energy consumption, associated with traditional dyeing processes.\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1267
  ]
1268
  }
1269
  ],
@@ -1291,7 +1327,7 @@
1291
  "import hashlib\n",
1292
  "from tqdm import tqdm\n",
1293
  "from dotenv import load_dotenv\n",
1294
- "\n",
1295
  "load_dotenv()\n",
1296
  "\n",
1297
  "# --- Configuration ---\n",
@@ -1486,17 +1522,19 @@
1486
  "\n",
1487
  "# --- Generation System ---\n",
1488
  "SYSTEM_PROMPT = \"\"\"\n",
1489
- "**Biomimicry Expert Guidelines**\n",
1490
  "\n",
1491
- "- Use only the provided AskNature context (e.g., Source, Application, Strategy, technical_concepts). If no context is given, note that you're using your own expertise.\n",
1492
- "- When referencing facts, use numeric citations in square brackets (e.g., [1]). Do not include full URLs inline.\n",
1493
- "- Bold all technical terms (e.g., **protein-based pigmentation**, **DNA-level fiber design**).\n",
1494
- "- Provide a concise, expert answer that explains the innovation and its sustainability benefits.\n",
1495
- "- End your response with a \"References\" section listing each URL with its citation number.\n",
 
1496
  "\n",
1497
  "Context: {context}\n",
1498
  "\"\"\"\n",
1499
  "\n",
 
1500
  "@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=20))\n",
1501
  "def get_ai_response(query: str, context: str, model: str) -> str:\n",
1502
  " result = \"\" # Initialize the result variable\n",
@@ -1570,7 +1608,6 @@
1570
  " except requests.exceptions.RequestException as e:\n",
1571
  " logger.error(f\"Groq API Error: {str(e)}\")\n",
1572
  " return \"An error occurred while contacting Groq's Llama 3 model.\"\n",
1573
- "\n",
1574
  "# --- Pipeline ---\n",
1575
  "documents = load_and_chunk_data(data_file_name)\n",
1576
  "retriever = EnhancedRetriever(documents)\n",
@@ -1584,7 +1621,15 @@
1584
  " return \"An error occurred processing your request.\"\n",
1585
  "\n",
1586
  "# --- Gradio Interface ---\n",
1587
- "def chat_interface(question: str, history: List[Tuple[str, str]], model: str):\n",
 
 
 
 
 
 
 
 
1588
  " response = generate_response(question, model)\n",
1589
  " return \"\", history + [(question, response)]\n",
1590
  "\n",
@@ -1594,7 +1639,7 @@
1594
  " chatbot = gr.Chatbot(label=\"Dialogue History\", height=500)\n",
1595
  " with gr.Row():\n",
1596
  " question = gr.Textbox(placeholder=\"Ask about biomimicry (e.g. 'How does Werewool use coral proteins to make fibers?')\", label=\"Inquiry\", scale=4)\n",
1597
- " model_selector = gr.Dropdown(choices=[\"gemini-2.0-flash\", \"meta-llama-3-70b-instruct(GWDG)\", \"llama3-70b-8192(Groq)\"], label=\"Generation Model\", value=\"gemini-2.0-flash\")\n",
1598
  " clear_btn = gr.Button(\"Clear History\", variant=\"secondary\")\n",
1599
  "\n",
1600
  " gr.Markdown(\"\"\"\n",
@@ -1610,6 +1655,20 @@
1610
  " demo.launch(show_error=True)\n"
1611
  ]
1612
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1613
  {
1614
  "cell_type": "code",
1615
  "execution_count": null,
 
1194
  "INFO:__main__:Loading cached documents\n",
1195
  "INFO:__main__:Loading cached BM25 index\n",
1196
  "INFO:__main__:Loading cached FAISS index\n",
1197
+ "INFO:faiss.loader:Loading faiss with AVX2 support.\n",
1198
+ "INFO:faiss.loader:Successfully loaded faiss with AVX2 support.\n",
1199
  "c:\\Users\\Mohamed Elsafty\\.conda\\envs\\rag\\Lib\\site-packages\\gradio\\components\\chatbot.py:273: UserWarning: You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.\n",
1200
  " warnings.warn(\n"
1201
  ]
 
1204
  "name": "stdout",
1205
  "output_type": "stream",
1206
  "text": [
1207
+ "* Running on local URL: http://127.0.0.1:7860\n"
1208
  ]
1209
  },
1210
  {
1211
  "name": "stderr",
1212
  "output_type": "stream",
1213
  "text": [
1214
+ "INFO:httpx:HTTP Request: GET http://127.0.0.1:7860/gradio_api/startup-events \"HTTP/1.1 200 OK\"\n",
1215
+ "INFO:httpx:HTTP Request: HEAD http://127.0.0.1:7860/ \"HTTP/1.1 200 OK\"\n"
1216
  ]
1217
  },
1218
  {
 
1226
  {
1227
  "data": {
1228
  "text/html": [
1229
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
1230
  ],
1231
  "text/plain": [
1232
  "<IPython.core.display.HTML object>"
 
1242
  "INFO:httpx:HTTP Request: GET https://api.gradio.app/pkg-version \"HTTP/1.1 200 OK\"\n",
1243
  "INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
1244
  "Embedding Progress: 0%| | 0/1 [00:00<?, ?it/s]INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/embeddings \"HTTP/1.1 200 OK\"\n",
1245
+ "Embedding Progress: 100%|██████████| 1/1 [00:00<00:00, 5.22it/s]\n",
1246
+ "INFO:__main__:Response from gemini-2.0-flash: Hello! I will provide detailed technical insights based on the biomimicry examples you've provided.\n",
1247
  "\n",
1248
+ "**1. Biodegradable Fibers Inspired by Discosoma Coral**\n",
1249
  "\n",
1250
+ "The textile industry's significant environmental impact, including high CO2 emissions, wastewater pollution from dyes, and microplastic pollution from synthetic fibers, necessitates sustainable alternatives [1]. **Werewool** addresses this by creating biodegradable fibers inspired by the **protein-based pigmentation** found in Discosoma coral [1].\n",
1251
  "\n",
1252
+ "* **Technical Details**: Werewool designs fibers at the **DNA level**, utilizing **biotechnology** to imbue them with inherent properties like color. This approach eliminates the need for toxic chemical dyes [1]. The use of **red fluorescent protein** from corals allows for vibrant, sustainable coloration [1].\n",
1253
+ "* **Innovation**: The innovation lies in engineering fibers with tailored aesthetic and performance properties directly at the genetic level, resulting in fully **biodegradable fibers** [1].\n",
1254
+ "* **Sustainability**: Reduces CO2 emissions, eliminates toxic dye usage, and mitigates microplastic pollution [1].\n",
1255
  "\n",
1256
+ "**2. Impact Resistance Inspired by Pummelo Peel**\n",
1257
+ "\n",
1258
+ "The pummelo fruit exhibits exceptional impact resistance due to the **hierarchical organization** of its peel (**pericarp**) [2].\n",
1259
+ "\n",
1260
+ "* **Technical Details**: The pericarp's structure provides excellent **damping properties**, allowing the fruit to withstand drops from significant heights without damage [2]. The **Young's modulus** and **structural composition** contribute to its ability to absorb and dissipate energy [2].\n",
1261
+ "* **Potential Applications**: The **composite materials** design principles from the pummelo peel can be applied to create impact-resistant materials in various industries, such as protective gear, packaging, and construction [2].\n",
1262
+ "* **Sustainability**: Developing materials based on natural hierarchical structures can lead to more durable and sustainable products, reducing the need for frequent replacements and minimizing waste [2].\n",
1263
+ "\n",
1264
+ "**3. Wind-Powered HVAC Inspired by Leaf-Cutting Ant Nests**\n",
1265
+ "\n",
1266
+ "Leaf-cutter ants construct nest structures with turrets that facilitate **wind-driven ventilation** [3].\n",
1267
+ "\n",
1268
+ "* **Technical Details**: The turret-like structures optimize airflow, enhancing ventilation within the nest. This principle can be applied in **HVAC engineering** to improve energy efficiency in buildings [3].\n",
1269
+ "* **Applications**: Mimicking the ant nest design can enhance ventilation in greenhouses, indoor farms, and buildings, reducing the reliance on fossil fuels for cooling and ventilation [3].\n",
1270
+ "* **Sustainability**: Implementing **biomimicry** in building design reduces energy consumption, lowers costs, and decreases the carbon footprint associated with traditional HVAC systems [3].\n",
1271
+ "\n",
1272
+ "**4. Sound Wave Concentration Inspired by Mammalian Ear-Flaps**\n",
1273
+ "\n",
1274
+ "Mammals' external ear-flaps concentrate sound waves, enhancing hearing [4].\n",
1275
+ "\n",
1276
+ "* **Technical Details**: The **ear-flap anatomy** is designed to efficiently collect and focus sound waves toward the inner ear, improving auditory perception [4].\n",
1277
+ "* **Potential Applications**: This principle can inspire the design of more efficient microphones, hearing aids, and acoustic sensors [4].\n",
1278
+ "* **Innovation**: Enhancing sound capture and directionality through biomimicry could lead to advancements in audio technology and assistive devices [4].\n",
1279
  "\n",
1280
+ "**5. Coordinated Movements in Starlings: Application to Edible Digital Detox**\n",
1281
  "\n",
1282
+ "While the provided context discusses macrophage response and immune cell communication inspired by starlings, the application \"edible digital detox\" is not directly supported by the provided text [5]. The information relates more to designing response guidelines for threatening situations by observing how immune cells react dynamically to threats [5].\n",
 
 
 
1283
  "\n",
1284
+ "* **Technical Details**: Observing how **macrophages** ensure immune systems don't overreact and how immune cells coordinate their efforts can provide insights for managing complex scenarios [5].\n",
1285
+ "* **Potential Applications**: The principles of coordinated response can be applied to emergency evacuation protocols or managing systemic responses in various fields [5].\n",
1286
+ "\n",
1287
+ "**Conclusion**\n",
1288
+ "\n",
1289
+ "Biomimicry offers innovative and sustainable solutions by emulating nature's designs and processes. From biodegradable textiles inspired by coral proteins to energy-efficient ventilation systems based on ant nests, these technologies can significantly reduce environmental impact and improve resource utilization. The key benefits include reduced CO2 emissions, decreased reliance on toxic chemicals, and enhanced energy efficiency.\n",
1290
+ "\n",
1291
+ "**References**\n",
1292
+ "\n",
1293
+ "1. [discosoma coral's protein](https://asknature.org/innovation/colorful-fibers-inspired-by-proteins-found-in-discosoma-coral/)\n",
1294
+ "2. [pummelo peel](https://asknature.org/strategy/hierarchical-organization-of-peel-confers-impact-resistance/)\n",
1295
+ "3. [leaf-cutting ant's nest](https://asknature.org/strategy/turrets-ventilate-nest/)\n",
1296
+ "4. [mammals' external ear‑flaps](https://asknature.org/strategy/ear-flaps-concentrate-sound-waves/)\n",
1297
+ "5. [starlings](https://asknature.org/strategy/starlings-coordinate-movements-within-a-flock/)\n",
1298
+ "\n",
1299
+ "INFO:httpx:HTTP Request: POST https://chat-ai.academiccloud.de/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
1300
+ "INFO:__main__:Response from meta-llama-3-70b-instruct: ChatCompletion(id='chat-532ee07e61864aaebacbd1b83d06752e', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"Hello. I'm an expert biomimicry advisor, and I'm here to provide you with detailed technical insights on biomimicry. Biomimicry is the practice of using nature as a source of inspiration to develop innovative solutions for human challenges. It involves studying the strategies and mechanisms that have evolved in nature to solve problems, and then applying those principles to develop new technologies, products, and systems.\\n\\nIn the context of the sources provided, we can see several examples of biomimicry in action. For instance, the Discosoma coral's protein-based pigmentation has inspired the development of biodegradable fibers with tailored aesthetic and performance properties [1]. This innovation has the potential to reduce the environmental impact of the textile industry, which is currently responsible for 1.2 billion tons of CO2 equivalent per year and 20% of global wastewater.\\n\\nAnother example is the hierarchical organization of the pummelo peel, which has inspired the development of composite materials with excellent mechanical properties [2]. The peel's hierarchical organization, which includes a combination of hard and soft materials, provides excellent damping properties, making it resistant to impact.\\n\\nThe leaf-cutting ant's nest is another example of biomimicry in action. The ant's use of turret-like structures to ventilate its nest has inspired the development of wind-powered HVAC engineering systems [3]. These systems have the potential to reduce energy consumption and greenhouse gas emissions in buildings.\\n\\nThe external ear-flaps of mammals have also inspired the development of sound wave concentration systems [4]. The ear-flaps' ability to collect and concentrate sound waves has led to the development of more efficient sound collection systems.\\n\\nFinally, the starlings' ability to coordinate their movements within a flock has inspired the development of response guidelines for potentially threatening situations [5]. The dynamic way that starlings respond to threats can provide insights into how to design more effective response systems.\\n\\nIn conclusion, biomimicry has the potential to inspire innovative solutions to a wide range of human challenges. By studying the strategies and mechanisms that have evolved in nature, we can develop new technologies, products, and systems that are more sustainable, efficient, and effective.\\n\\nReferences:\\n\\n[1] Werewool. (n.d.). Colorful Textiles Inspired by Proteins Found in Discosoma Coral. AskNature.\\n\\n[2] Hierarchical Organization of Peel Confers Impact Resistance. (n.d.). AskNature.\\n\\n[3] Turrets Ventilate Nest. (n.d.). AskNature.\\n\\n[4] Ear-flaps Concentrate Sound Waves. (n.d.). AskNature.\\n\\n[5] Starlings Coordinate Movements within a Flock. (n.d.). AskNature.\", refusal=None, role='assistant', audio=None, function_call=None, tool_calls=[]), stop_reason=None)], created=1739188665, model='meta-llama-3.1-70b-instruct', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=543, prompt_tokens=1156, total_tokens=1699, completion_tokens_details=None, prompt_tokens_details=None), prompt_logprobs=None)\n",
1301
+ "INFO:__main__:Groq API Response: {'id': 'chatcmpl-a5a2cc71-464e-4d16-9cd7-74226d93cbbf', 'object': 'chat.completion', 'created': 1739188697, 'model': 'llama3-70b-8192', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': \"Hello! It's nice to meet you. Is there something I can help you with, or would you like to chat?\"}, 'logprobs': None, 'finish_reason': 'stop'}], 'usage': {'queue_time': 0.259490815, 'prompt_tokens': 11, 'prompt_time': 0.003311302, 'completion_tokens': 26, 'completion_time': 0.076609847, 'total_tokens': 37, 'total_time': 0.079921149}, 'system_fingerprint': 'fp_753a4aecf6', 'x_groq': {'id': 'req_01jkqvjxpvek4bvzmsq09wkacs'}}\n",
1302
+ "INFO:__main__:Response from llama3-70b-8192: Hello! It's nice to meet you. Is there something I can help you with, or would you like to chat?\n"
1303
  ]
1304
  }
1305
  ],
 
1327
  "import hashlib\n",
1328
  "from tqdm import tqdm\n",
1329
  "from dotenv import load_dotenv\n",
1330
+ "import pickle\n",
1331
  "load_dotenv()\n",
1332
  "\n",
1333
  "# --- Configuration ---\n",
 
1522
  "\n",
1523
  "# --- Generation System ---\n",
1524
  "SYSTEM_PROMPT = \"\"\"\n",
1525
+ "**Expert Biomimicry Advisor**\n",
1526
  "\n",
1527
+ "- **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.\n",
1528
+ "- **Answer Precision**: Always use precise technical language and structure your response logically, emphasizing the relationship between biological concepts and innovation.\n",
1529
+ "- **References**: Use numeric citations (e.g., [1]) when referencing data points or studies, corresponding to the URLs or sources provided in the context.\n",
1530
+ "- **Content Formatting**: Bold technical terms for emphasis (e.g., **protein synthesis**, **ecosystem mimicry**).\n",
1531
+ "- **Conclusion**: Summarize the sustainability impacts of the discussed technologies or ideas. Highlight innovative aspects and benefits.\n",
1532
+ "- **References Section**: At the end of your response, list all cited sources with their corresponding numbers.\n",
1533
  "\n",
1534
  "Context: {context}\n",
1535
  "\"\"\"\n",
1536
  "\n",
1537
+ "\n",
1538
  "@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=20))\n",
1539
  "def get_ai_response(query: str, context: str, model: str) -> str:\n",
1540
  " result = \"\" # Initialize the result variable\n",
 
1608
  " except requests.exceptions.RequestException as e:\n",
1609
  " logger.error(f\"Groq API Error: {str(e)}\")\n",
1610
  " return \"An error occurred while contacting Groq's Llama 3 model.\"\n",
 
1611
  "# --- Pipeline ---\n",
1612
  "documents = load_and_chunk_data(data_file_name)\n",
1613
  "retriever = EnhancedRetriever(documents)\n",
 
1621
  " return \"An error occurred processing your request.\"\n",
1622
  "\n",
1623
  "# --- Gradio Interface ---\n",
1624
+ "# Define the mapping from display names to actual model identifiers\n",
1625
+ "model_mapping = {\n",
1626
+ " \"Gemini-2.0-Flash\": \"gemini-2.0-flash\",\n",
1627
+ " \"Meta-llama-3-70b-instruct(GWDG)\": \"meta-llama-3-70b-instruct\",\n",
1628
+ " \"llama3-70b-8192(Groq)\": \"llama3-70b-8192\"\n",
1629
+ "}\n",
1630
+ "\n",
1631
+ "def chat_interface(question: str, history: List[Tuple[str, str]], display_model: str):\n",
1632
+ " model = model_mapping.get(display_model, \"gemini-2.0-flash\") # Default to Gemini if not found\n",
1633
  " response = generate_response(question, model)\n",
1634
  " return \"\", history + [(question, response)]\n",
1635
  "\n",
 
1639
  " chatbot = gr.Chatbot(label=\"Dialogue History\", height=500)\n",
1640
  " with gr.Row():\n",
1641
  " question = gr.Textbox(placeholder=\"Ask about biomimicry (e.g. 'How does Werewool use coral proteins to make fibers?')\", label=\"Inquiry\", scale=4)\n",
1642
+ " model_selector = gr.Dropdown(choices=list(model_mapping.keys()), label=\"Generation Model\", value=\"Gemini-2.0-Flash\")\n",
1643
  " clear_btn = gr.Button(\"Clear History\", variant=\"secondary\")\n",
1644
  "\n",
1645
  " gr.Markdown(\"\"\"\n",
 
1655
  " demo.launch(show_error=True)\n"
1656
  ]
1657
  },
1658
+ {
1659
+ "cell_type": "code",
1660
+ "execution_count": null,
1661
+ "metadata": {},
1662
+ "outputs": [],
1663
+ "source": []
1664
+ },
1665
+ {
1666
+ "cell_type": "code",
1667
+ "execution_count": null,
1668
+ "metadata": {},
1669
+ "outputs": [],
1670
+ "source": []
1671
+ },
1672
  {
1673
  "cell_type": "code",
1674
  "execution_count": null,
requirements.txt CHANGED
@@ -20,4 +20,4 @@ huggingface_hub
20
  tqdm
21
  sentence-transformers
22
  google-generativeai
23
- groq
 
20
  tqdm
21
  sentence-transformers
22
  google-generativeai
23
+