Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
|
7 |
+
st.set_page_config(
|
8 |
+
page_title="MediAssist - Prescription Analyzer",
|
9 |
+
layout="wide",
|
10 |
+
page_icon="💊"
|
11 |
+
)
|
12 |
+
|
13 |
+
# Sidebar
|
14 |
+
st.sidebar.image("https://cdn-icons-png.flaticon.com/512/2965/2965567.png", width=100)
|
15 |
+
st.sidebar.title("💊 MediAssist")
|
16 |
+
st.sidebar.markdown("Analyze prescriptions with ease using AI")
|
17 |
+
st.sidebar.markdown("---")
|
18 |
+
st.sidebar.markdown("👤 Developed by Yash Jadhav")
|
19 |
+
|
20 |
+
# Main Title
|
21 |
+
st.markdown("""
|
22 |
+
<h1 style='text-align: center; color: #4A90E2;'>🧠 MediAssist</h1>
|
23 |
+
<h3 style='text-align: center;'>Prescription Analyzer using AI and OCR</h3>
|
24 |
+
<p style='text-align: center;'>Upload a doctor's prescription image, and MediAssist will extract, translate, and explain it for you.</p>
|
25 |
+
<br>
|
26 |
+
""", unsafe_allow_html=True)
|
27 |
+
|
28 |
+
# Image Upload
|
29 |
+
uploaded_file = st.file_uploader("📤 Upload Prescription Image (JPG/PNG)", type=["jpg", "jpeg", "png"])
|
30 |
+
|
31 |
+
# Columns for layout
|
32 |
+
col1, col2 = st.columns([1, 2])
|
33 |
+
|
34 |
+
if uploaded_file:
|
35 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
36 |
+
temp_file.write(uploaded_file.read())
|
37 |
+
temp_path = temp_file.name
|
38 |
+
|
39 |
+
# Read the image using OpenCV
|
40 |
+
image = cv2.imread(temp_path)
|
41 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
42 |
+
|
43 |
+
# Apply morphological transformations
|
44 |
+
kernel = np.ones((2, 2), np.uint8)
|
45 |
+
erosion = cv2.erode(gray, kernel, iterations=1)
|
46 |
+
dilation = cv2.dilate(erosion, kernel, iterations=1)
|
47 |
+
|
48 |
+
with col1:
|
49 |
+
st.image(dilation, caption="Preprocessed Prescription", channels="GRAY", use_column_width=True)
|
50 |
+
|
51 |
+
with col2:
|
52 |
+
st.success("✅ Prescription Uploaded & Preprocessed Successfully")
|
53 |
+
|
54 |
+
# Placeholder text (replace with actual OCR + LLM output later)
|
55 |
+
st.markdown("### 📜 Extracted Text")
|
56 |
+
st.code("Paracetamol 500mg\nTake 1 tablet twice a day after meals", language='text')
|
57 |
+
|
58 |
+
st.markdown("### 🌐 Translated Text")
|
59 |
+
st.code("पेरासिटामोल 500 मिलीग्राम\nभोजन के बाद दिन में दो बार 1 गोली लें", language='text')
|
60 |
+
|
61 |
+
st.markdown("### ⏱️ Tablet Timing & Instructions")
|
62 |
+
st.info("- Morning after breakfast\n- Night after dinner\n- Take with water\n- Do not exceed 2 tablets in 24 hours")
|
63 |
+
|
64 |
+
st.markdown("### ⚠️ Possible Side Effects")
|
65 |
+
st.warning("- Nausea\n- Dizziness\n- Liver damage (on overdose)")
|
66 |
+
|
67 |
+
os.remove(temp_path)
|
68 |
+
|
69 |
+
else:
|
70 |
+
st.image("https://cdn.dribbble.com/users/285475/screenshots/14711920/media/bd46dc2873f7099e4ef9fd53e6f7f1df.png", width=600)
|
71 |
+
st.markdown("<center><i>Upload a prescription image to begin analysis.</i></center>", unsafe_allow_html=True)
|