Spaces:
Sleeping
Sleeping
Efficient fix : for timing and character length
Browse filesEfficient fix : for timing to not overload the api service
Character length to not over load the search in database in case of the AI returned just 1 word
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import requests
|
|
| 5 |
import os
|
| 6 |
import gradio as gr
|
| 7 |
from smolagents import tool
|
|
|
|
| 8 |
|
| 9 |
#specialtoken=os.getenv("SPECIALTOKEN")+"deepseek-r1-0528"
|
| 10 |
specialtoken=os.getenv("SPECIALTOKEN")+"openai"#"openai-large"#"openai-roblox"
|
|
@@ -108,12 +109,12 @@ def get_unique_symptoms(list_text:List[str])->List[str]:
|
|
| 108 |
symptoms = text.replace(" and ", " ").replace(" been ", " ").replace(" also ", " ").replace(" like ", " ").replace(" due ", " ").replace(" a ", " ").replace(" as ", " ").replace(" an ", " ").replace(",", " ").replace(".", " ").replace(";", " ").replace("(", " ").replace(")", " ").split()
|
| 109 |
symptoms = [symptom.strip() for symptom in symptoms if symptom.strip()] # Remove extra whitespace and empty strings
|
| 110 |
all_symptoms.extend(symptoms)
|
| 111 |
-
elif type(text)==str:
|
| 112 |
symptoms = text.replace(" and ", " ").replace(" been ", " ").replace(" also ", " ").replace(" like ", " ").replace(" due ", " ").replace(" a ", " ").replace(" as ", " ").replace(" an ", " ").replace(",", " ").replace(".", " ").replace(";", " ").replace("(", " ").replace(")", " ").split()
|
| 113 |
symptoms = [symptom.strip() for symptom in symptoms if symptom.strip()] # Remove extra whitespace and empty strings
|
| 114 |
all_symptoms.extend(symptoms)
|
| 115 |
else:
|
| 116 |
-
print ("No Correct DataType")
|
| 117 |
#if not isinstance(text, str) or not text:
|
| 118 |
#continue
|
| 119 |
|
|
@@ -292,7 +293,7 @@ def full_treatment_answer_ai(user_input:str)->str:
|
|
| 292 |
all_related_plants.append(each)
|
| 293 |
plants_info=""
|
| 294 |
if len(all_related_plants)>0:
|
| 295 |
-
for each in all_related_plants[:
|
| 296 |
plants_info+="""Here are some plants that might be relevant:\nPlant:{each['name']}\n{each['description']}\nCures:{each['treatable_conditions']}.\n """
|
| 297 |
else:
|
| 298 |
plants_info="No Plants found , please get useful plants from anywhere or any other sources."
|
|
@@ -368,7 +369,8 @@ def is_symtoms_intext_ai(text_input:str)->str: #used instead of: analyze_symptom
|
|
| 368 |
response = requests.get(f"{fasttoken}/{prompt}")
|
| 369 |
response_text=response.text
|
| 370 |
if len(response_text)>2:
|
| 371 |
-
|
|
|
|
| 372 |
return ""
|
| 373 |
|
| 374 |
class BotanistAssistant:
|
|
@@ -511,6 +513,7 @@ class BotanistAssistant:
|
|
| 511 |
treatment_response=""
|
| 512 |
symtoms_intext=is_symtoms_intext_ai(message)
|
| 513 |
if symtoms_intext:
|
|
|
|
| 514 |
treatment_response=full_treatment_answer_ai(symtoms_intext)
|
| 515 |
#yield treatment_response
|
| 516 |
|
|
@@ -553,8 +556,8 @@ def create_app(api_endpoint: str) -> gr.Blocks:
|
|
| 553 |
gr.Examples(
|
| 554 |
examples=[
|
| 555 |
["I have headache and fever"],
|
| 556 |
-
["nausea, and injury caused bleeding"],
|
| 557 |
-
["insomnia, anxiety"]
|
| 558 |
],
|
| 559 |
inputs=chat.textbox,
|
| 560 |
label="Try these examples"
|
|
|
|
| 5 |
import os
|
| 6 |
import gradio as gr
|
| 7 |
from smolagents import tool
|
| 8 |
+
import time
|
| 9 |
|
| 10 |
#specialtoken=os.getenv("SPECIALTOKEN")+"deepseek-r1-0528"
|
| 11 |
specialtoken=os.getenv("SPECIALTOKEN")+"openai"#"openai-large"#"openai-roblox"
|
|
|
|
| 109 |
symptoms = text.replace(" and ", " ").replace(" been ", " ").replace(" also ", " ").replace(" like ", " ").replace(" due ", " ").replace(" a ", " ").replace(" as ", " ").replace(" an ", " ").replace(",", " ").replace(".", " ").replace(";", " ").replace("(", " ").replace(")", " ").split()
|
| 110 |
symptoms = [symptom.strip() for symptom in symptoms if symptom.strip()] # Remove extra whitespace and empty strings
|
| 111 |
all_symptoms.extend(symptoms)
|
| 112 |
+
elif type(text)==str and len(text)>1:
|
| 113 |
symptoms = text.replace(" and ", " ").replace(" been ", " ").replace(" also ", " ").replace(" like ", " ").replace(" due ", " ").replace(" a ", " ").replace(" as ", " ").replace(" an ", " ").replace(",", " ").replace(".", " ").replace(";", " ").replace("(", " ").replace(")", " ").split()
|
| 114 |
symptoms = [symptom.strip() for symptom in symptoms if symptom.strip()] # Remove extra whitespace and empty strings
|
| 115 |
all_symptoms.extend(symptoms)
|
| 116 |
else:
|
| 117 |
+
print ("No Correct DataType or 1 charater text O.o")
|
| 118 |
#if not isinstance(text, str) or not text:
|
| 119 |
#continue
|
| 120 |
|
|
|
|
| 293 |
all_related_plants.append(each)
|
| 294 |
plants_info=""
|
| 295 |
if len(all_related_plants)>0:
|
| 296 |
+
for each in all_related_plants[:6]: #GET top 7 if available
|
| 297 |
plants_info+="""Here are some plants that might be relevant:\nPlant:{each['name']}\n{each['description']}\nCures:{each['treatable_conditions']}.\n """
|
| 298 |
else:
|
| 299 |
plants_info="No Plants found , please get useful plants from anywhere or any other sources."
|
|
|
|
| 369 |
response = requests.get(f"{fasttoken}/{prompt}")
|
| 370 |
response_text=response.text
|
| 371 |
if len(response_text)>2:
|
| 372 |
+
if "error" not in response_text.lower():
|
| 373 |
+
return response_text
|
| 374 |
return ""
|
| 375 |
|
| 376 |
class BotanistAssistant:
|
|
|
|
| 513 |
treatment_response=""
|
| 514 |
symtoms_intext=is_symtoms_intext_ai(message)
|
| 515 |
if symtoms_intext:
|
| 516 |
+
time.sleep(1.6)
|
| 517 |
treatment_response=full_treatment_answer_ai(symtoms_intext)
|
| 518 |
#yield treatment_response
|
| 519 |
|
|
|
|
| 556 |
gr.Examples(
|
| 557 |
examples=[
|
| 558 |
["I have headache and fever"],
|
| 559 |
+
["got nausea, and injury caused bleeding"],
|
| 560 |
+
["I feel insomnia, and anxiety"]
|
| 561 |
],
|
| 562 |
inputs=chat.textbox,
|
| 563 |
label="Try these examples"
|