Spaces:
Sleeping
Sleeping
|
Download APP_FLOW.md from bnewcomer/MediBot: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/bnewcomer/MediBot/resolve/main/APP_FLOW.md
- Command line
-
hf download hf://spaces/bnewcomer/MediBot/APP_FLOW.md
-
curl -L -o APP_FLOW.md https://huggingface.co/spaces/bnewcomer/MediBot/resolve/main/APP_FLOW.md
3.56 kB
A newer version of the Gradio SDK is available: 6.32.0
App Flow Diagram
This diagram shows the main code path for starting the app and processing a user prompt.
Startup and Prompt Flow
flowchart TD
A["python app.py"] --> B["MedicalChatbotApp()"]
B --> C["load_datasets()"]
C --> D["Create agents"]
D --> D1["DiseaseDiagnosisAgent"]
D --> D2["ClarificationAgent"]
D --> D3["SymptomSeverityAgent"]
D --> D4["DiseaseDescriptionAgent"]
D --> D5["PrecautionAdvisorAgent"]
D1 --> E["build_faiss_index(df)"]
D1 --> F["build_tfidf_matrix(collapsed_df)"]
D --> G["ReActRouter(agents, all_symptoms)"]
G --> H["launch()"]
H --> I["Gradio UI shown"]
I --> J["User submits prompt"]
J --> K["respond(msg, state)"]
K --> L["chat(user_input, session_state)"]
L --> M["extract_structured_context()"]
M --> N["merge_structured_context()"]
N --> O["router.plan(user_input, history, structured_context)"]
O --> P{"Planner output valid?"}
P -- "Yes" --> Q["Executable steps"]
P -- "No" --> R["router._fallback_plan()"]
R --> Q
Q --> S["_execute_plan()"]
S --> T{"Agent step type"}
T -- "clarification_agent" --> U["ClarificationAgent.handle()"]
T -- "symptom_severity" --> V["SymptomSeverityAgent.handle()"]
T -- "disease_diagnosis" --> W["DiseaseDiagnosisAgent.handle()"]
T -- "disease_description" --> X["DiseaseDescriptionAgent.handle()"]
T -- "precaution_advisor" --> Y["PrecautionAdvisorAgent.handle()"]
W --> W1["normalize_symptom() / map_to_known_symptoms()"]
W1 --> W2["build_user_vector()"]
W1 --> W3["build_user_tfidf_vector()"]
W2 --> W4["FAISS search"]
W3 --> W5["score_candidates()"]
W4 --> W5
W5 --> W6{"Top scores close?"}
W6 -- "Yes" --> W7["LLMReranker.rerank()"]
W6 -- "No" --> W8["Keep scored ranking"]
W7 --> Z["diagnosis result"]
W8 --> Z
U --> AA["clarification result"]
V --> AB["severity result"]
X --> AC["description result"]
Y --> AD["precaution result"]
Z --> AE["Format answer"]
AA --> AE
AB --> AE
AC --> AE
AD --> AE
AE --> AF{"Red flags or ambiguity?"}
AF -- "Emergency" --> AG["_format_emergency_answer()"]
AF -- "Needs clarification" --> AH["_format_clarification_answer()"]
AF -- "Diagnosis/details" --> AI["_format_diagnosis_answer() or detail response"]
AG --> AJ["Update session state"]
AH --> AJ
AI --> AJ
AJ --> AK["_render_session_summary()"]
AJ --> AL["_render_result_card()"]
AK --> AM["Return history, state, summary, card_html"]
AL --> AM
Main Files Involved
app.py: app startup, router, session state, prompt processing, response formatting, and Gradio UIdiagnosis_engine/diagnosis_agent.py: diagnosis pipeline orchestrationdiagnosis_engine/faiss_index.py: symptom vector indexing and retrievaldiagnosis_engine/tfidf.py: TF-IDF symptom similaritydiagnosis_engine/scoring.py: candidate scoring and rankingdiagnosis_engine/vocabulary.py: symptom normalization and synonym mappingdiagnosis_engine/reranker.py: optional LLM reranking for close candidates
Practical Reading Order
If you want to trace the code manually, this is the most useful order:
app.py->MedicalChatbotApp.__init__()app.py->launch()app.py->chat()app.py->ReActRouter.plan()app.py->_execute_plan()diagnosis_engine/diagnosis_agent.py->handle()diagnosis_engine/scoring.py->score_candidates()app.py->_format_*_answer()methods