mgbam commited on
Commit
40450f3
Β·
verified Β·
1 Parent(s): 943c488

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md CHANGED
@@ -9,5 +9,151 @@ app_file: app.py
9
  pinned: false
10
  short_description: Medical Image
11
  ---
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  pinned: false
10
  short_description: Medical Image
11
  ---
12
+ # MedSketch AI – Advanced Clinical Diagram Generator πŸ–ΌοΈ
13
 
14
+ **MedSketch AI** is a web application built with Streamlit that leverages cutting-edge AI models (like OpenAI's DALL-E 3 via the GPT-4o API endpoint access) to generate medical diagrams and illustrations from text prompts. It allows users to specify styles, associate metadata, perform batch generation, annotate the results, and export annotations.
15
+
16
+ [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://your-deployed-app-url.com) <!-- Replace with your deployment URL -->
17
+ <!-- Add other badges if applicable (e.g., license, build status) -->
18
+
19
+ [Insert Screenshot/GIF of the App Here - Highly Recommended!]
20
+ *A visual demonstration of MedSketch AI in action.*
21
+
22
+ ---
23
+
24
+ ## ✨ Features
25
+
26
+ * **AI-Powered Generation:** Create medical diagrams using models like OpenAI's DALL-E 3 (accessed via API). (Placeholder for Stable Diffusion LoRA integration).
27
+ * **Style Presets & Customization:** Apply predefined styles (Anatomical, H&E, IHC) or define custom styles. Control stylization strength.
28
+ * **Batch Processing:** Generate multiple diagrams simultaneously by entering one prompt per line.
29
+ * **Metadata Association:** Tag generated images with optional Patient ID, Region of Interest (ROI), and UMLS/SNOMED CT codes.
30
+ * **Interactive Annotation:** Draw annotations (freehand) directly onto the generated images using `streamlit-drawable-canvas`.
31
+ * **Session History:** Keep track of generated images and their associated metadata within the current session.
32
+ * **Annotation Export:** Download all annotations made during the session as a structured JSON file, including associated metadata and generation details.
33
+ * **Robust Error Handling:** Provides informative feedback on API errors or other issues.
34
+ * **Configurable:** Easy setup using Streamlit Secrets or environment variables for API keys.
35
+ * **Clear History:** Option to clear the session history and annotations.
36
+
37
+ ## Prerequisites
38
+
39
+ * **Python:** Version 3.8 or higher recommended.
40
+ * **pip:** Python package installer.
41
+ * **Git:** For cloning the repository.
42
+ * **OpenAI API Key:** You need an API key from OpenAI to use the DALL-E 3 / GPT-4o generation features.
43
+
44
+ ## πŸš€ Installation & Setup
45
+
46
+ 1. **Clone the Repository:**
47
+ ```bash
48
+ git clone https://github.com/your-username/medsketch-ai.git # Replace with your repo URL
49
+ cd medsketch-ai
50
+ ```
51
+
52
+ 2. **Create `requirements.txt`:**
53
+ Create a file named `requirements.txt` in the project root with the following content:
54
+ ```txt
55
+ streamlit
56
+ openai
57
+ streamlit-drawable-canvas
58
+ Pillow
59
+ requests
60
+ ```
61
+
62
+ 3. **Install Dependencies:**
63
+ ```bash
64
+ pip install -r requirements.txt
65
+ ```
66
+
67
+ 4. **Configure OpenAI API Key:**
68
+ You **must** provide your OpenAI API key. There are two primary methods:
69
+
70
+ * **a) Streamlit Secrets (Recommended for Deployment):**
71
+ * Create a directory named `.streamlit` in your project root if it doesn't exist.
72
+ * Inside `.streamlit`, create a file named `secrets.toml`.
73
+ * Add your API key to `secrets.toml`:
74
+ ```toml
75
+ # .streamlit/secrets.toml
76
+ OPENAI_API_KEY="sk-YourSecretOpenAI_ApiKeyGoesHere"
77
+ ```
78
+ * **Important:** Ensure `.streamlit/secrets.toml` is added to your `.gitignore` file to prevent accidentally committing your secret key.
79
+
80
+ * **b) Environment Variable (Good for Local Development):**
81
+ * Set the `OPENAI_API_KEY` environment variable in your terminal session:
82
+ * **Linux/macOS:**
83
+ ```bash
84
+ export OPENAI_API_KEY='sk-YourSecretOpenAI_ApiKeyGoesHere'
85
+ ```
86
+ * **Windows (Command Prompt):**
87
+ ```bash
88
+ set OPENAI_API_KEY=sk-YourSecretOpenAI_ApiKeyGoesHere
89
+ ```
90
+ * **Windows (PowerShell):**
91
+ ```bash
92
+ $env:OPENAI_API_KEY='sk-YourSecretOpenAI_ApiKeyGoesHere'
93
+ ```
94
+ * The application will automatically look for this environment variable if the Streamlit secret is not found.
95
+
96
+ ## ▢️ Running the Application
97
+
98
+ Once the dependencies are installed and the API key is configured, run the Streamlit app from your project's root directory:
99
+
100
+ ```bash
101
+ streamlit run app.py
102
+ Use code with caution.
103
+ Markdown
104
+ Your default web browser should automatically open to the application's URL (usually http://localhost:8501).
105
+ πŸ“– Usage Guide
106
+ Configure Settings (Sidebar):
107
+ Select Model: Choose between "GPT-4o (API)" (uses DALL-E 3) or the placeholder "Stable Diffusion LoRA".
108
+ Select Preset Style: Choose a visual style like "Anatomical Diagram", "H&E Histology", etc., or select "Custom" and enter your own style description.
109
+ Stylization Strength: Adjust the slider to control how strongly the style influences the output (this is conceptually passed in the prompt).
110
+ (Optional) Metadata: Enter relevant Patient/Case ID, ROI, or UMLS/SNOMED codes. These will be associated with the generated images in the history and export.
111
+ Enter Prompts (Main Area):
112
+ In the text area, describe the medical diagram(s) you want to generate.
113
+ For batch generation, enter one prompt per line.
114
+ Generate:
115
+ Click the "πŸš€ Generate Diagram(s)" button.
116
+ View Results:
117
+ Generated images will appear below the button, organized in columns.
118
+ Each result includes the image, the prompt used, and a download button (⬇️ Download PNG).
119
+ Annotate (Optional):
120
+ Below each image, an annotation canvas (✏️ Annotate:) is provided.
121
+ Use your mouse to draw directly on the image (default is freehand red lines).
122
+ Annotations are automatically saved to the session state.
123
+ Review History & Export Annotations (Bottom Section):
124
+ The "πŸ“š Session History & Annotations" section appears once generations are complete.
125
+ It lists the prompts used, model/style settings, and associated metadata for each generated item.
126
+ You can expand each item to view the raw JSON data of any annotations made.
127
+ Click "⬇️ Export All Annotations (JSON)" to download a JSON file containing all annotations from the current session, enriched with metadata and generation details.
128
+ Clear History (Sidebar):
129
+ Use the "⚠️ Clear History & Annotations" button in the sidebar to reset the session.
130
+ πŸ› οΈ Technology Stack
131
+ Framework: Streamlit
132
+ AI Generation: OpenAI API (DALL-E 3)
133
+ Annotation: streamlit-drawable-canvas
134
+ Image Handling: Pillow (PIL Fork)
135
+ API Requests: requests (for image download if using URL format)
136
+ Language: Python
137
+ πŸ’‘ Future Enhancements (Roadmap)
138
+ Implement actual Stable Diffusion LoRA model integration.
139
+ Support for additional AI image generation models.
140
+ More advanced annotation tools (shapes, text, colors).
141
+ Ability to load/edit existing annotations.
142
+ Improved image storage/retrieval in session state (potentially using caching or temporary files).
143
+ User accounts and persistent storage (beyond session).
144
+ More sophisticated prompt engineering assistance.
145
+ πŸ™ Contributing
146
+ Contributions are welcome! If you have suggestions for improvements or find a bug, please feel free to:
147
+ Open an issue to discuss the change or report the bug.
148
+ Fork the repository, make your changes, and submit a pull request.
149
+ Please ensure your code follows basic Python best practices and includes documentation where necessary.
150
+ πŸ“œ License
151
+ This project is licensed under the MIT License - see the LICENSE.txt file for details.
152
+ (You should create a LICENSE.txt file in your repository containing the text of the MIT License or your chosen license).
153
+ **To make this README complete:**
154
+
155
+ 1. **Replace Placeholders:** Update `https://github.com/your-username/medsketch-ai.git` and `https://your-deployed-app-url.com` with your actual URLs.
156
+ 2. **Add Screenshot/GIF:** Capture a compelling visual of your app and embed it where indicated. This significantly improves understanding.
157
+ 3. **Create `LICENSE.txt`:** Add a file named `LICENSE.txt` to your repository containing the full text of the MIT license (or whichever license you choose). You can easily find standard license text online (e.g., choosealicense.com).
158
+ 4. **Commit `requirements.txt`:** Make sure the `requirements.txt` file described is actually created and committed to your repository.
159
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference