Yashvj123 commited on
Commit
d4b42e3
·
verified ·
1 Parent(s): 3f7d7a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
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
- # Columns for layout
51
- col1, col2 = st.columns([1, 2])
52
-
53
- dilated_path = orig_path.replace(".png", "_dilated.png")
54
- cv2.imwrite(dilated_path, dilated)
55
-
56
- # Load and extract text
57
- loader = UnstructuredImageLoader(dilated_path)
58
- documents = loader.load()
59
- extracted_text = "\n".join([doc.page_content for doc in documents])
60
-
61
- # Define prompt
62
- template = """
63
- You are a helpful assistant. Here is a prescription text extracted from an image:
64
-
65
- {prescription_text}
66
-
67
- Please summarize the key medicine names and instructions in bullet points.
68
- """
69
- prompt = PromptTemplate(input_variables=["prescription_text"], template=template)
 
 
 
 
 
 
70
 
71
- model = HuggingFaceEndpoint(
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
- chain = LLMChain(llm=model, prompt=prompt)
 
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)