Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -47,36 +47,37 @@ st.markdown("""
|
|
47 |
# Image Upload
|
48 |
uploaded_file = st.file_uploader("📤 Upload Prescription Image (JPG/PNG)", type=["jpg", "jpeg", "png"])
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
73 |
-
provider="novita",
|
74 |
-
temperature=0.6,
|
75 |
-
max_new_tokens=300,
|
76 |
-
task="conversational"
|
77 |
-
)
|
78 |
|
79 |
-
|
|
|
80 |
|
81 |
with col1:
|
82 |
st.image(dilated, caption="Preprocessed Prescription", channels="GRAY", use_container_width=True)
|
|
|
47 |
# Image Upload
|
48 |
uploaded_file = st.file_uploader("📤 Upload Prescription Image (JPG/PNG)", type=["jpg", "jpeg", "png"])
|
49 |
|
50 |
+
|
51 |
+
dilated_path = orig_path.replace(".png", "_dilated.png")
|
52 |
+
cv2.imwrite(dilated_path, dilated)
|
53 |
+
|
54 |
+
# Load and extract text
|
55 |
+
loader = UnstructuredImageLoader(dilated_path)
|
56 |
+
documents = loader.load()
|
57 |
+
extracted_text = "\n".join([doc.page_content for doc in documents])
|
58 |
+
|
59 |
+
# Define prompt
|
60 |
+
template = """
|
61 |
+
You are a helpful assistant. Here is a prescription text extracted from an image:
|
62 |
+
|
63 |
+
{prescription_text}
|
64 |
+
|
65 |
+
Please summarize the key medicine names and instructions in bullet points.
|
66 |
+
"""
|
67 |
+
prompt = PromptTemplate(input_variables=["prescription_text"], template=template)
|
68 |
+
|
69 |
+
model = HuggingFaceEndpoint(
|
70 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
71 |
+
provider="novita",
|
72 |
+
temperature=0.6,
|
73 |
+
max_new_tokens=300,
|
74 |
+
task="conversational"
|
75 |
+
)
|
76 |
|
77 |
+
chain = LLMChain(llm=model, prompt=prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
# Columns for layout
|
80 |
+
col1, col2 = st.columns([1, 2])
|
81 |
|
82 |
with col1:
|
83 |
st.image(dilated, caption="Preprocessed Prescription", channels="GRAY", use_container_width=True)
|