How mohtasham9/medical_prescription_parser works
Main Components
• User Interface (UI): This is the Streamlit web interface where users upload prescription images. Although the file tree does not explicitly list an “app.py,” the README instructs you to run the interface via Streamlit.
• Image Processing and Parsing Engine: Likely encapsulated in files such as prescription.py (and possibly parts of app.py). This component handles loading images, calling the GPT-4o API, and parsing the response into structured data.
• External API Service: The GPT-4o model provided by OpenAI. This service is called during the transcription process and is critical for extracting prescription details.
• Environment and Configuration Management: Represented by keys.py and environment setups, where the OpenAI API key is configured.
• Data Models & Validation: Handled via Pydantic models (mentioned in the README’s “Code Explanation” section) to ensure that the output data (medications, patient info, etc.) is properly structured.
• Styling Component: The styles.css file contains custom CSS that is applied to the Streamlit application for a better UI experience.
Relationships and Interactions
• The User interacts with the Streamlit UI by uploading images.
• The UI component then calls the backend processing logic (in prescription.py) to load and encode images.
• The processing logic triggers a call to the external GPT-4o API (utilizing the API key set up in keys.py) and passes a detailed prompt extracted from the prescription.
• The API returns a raw response which is then processed, with data validated and structured using the Pydantic models.
• The results are sent back to the UI layer where the Streamlit application displays the structured prescription information.
• Additionally, the UI applies custom styles from styles.css to ensure consistency and a polished presentation.
Architectural Patterns or Design Principles
• Layered Architecture: Clearly separate UI (presentation layer), business logic (processing, image parsing, API calls), and configuration services (environment keys, external API).
• API Integration: The prescription processing layer acts as an integration point between the application and the OpenAI GPT-4o service.
• Component Modularity: Each file (keys.py for config, prescription.py for processing, styles.css for styling) encapsulates a specific set of concerns, enabling easier maintenance and potential extensibility.
• Data Validation: The use of Pydantic models emphasizes the importance of ensuring that extracted data meets the required schema and quality.