Hypernova823 commited on
Commit
eb33491
Β·
verified Β·
1 Parent(s): fb27b84

Upload streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -16
src/streamlit_app.py CHANGED
@@ -110,24 +110,11 @@ div[data-testid="stFileUploader"] * {
110
 
111
  /* ═══════════════════════════════════════════════════════════════ */
112
 
113
- /* Stats & DYNAMIC Output Box */
114
  .stat-card { background: #000; padding: 15px; border-radius: 4px; text-align: center; border: 1px solid rgba(143, 245, 255, 0.1); margin-bottom: 10px; }
115
  .stat-val { color: #8ff5ff; font-size: 24px; font-weight: 700; font-family: 'Space Grotesk'; }
116
  .stat-lbl { font-size: 9px; color: #46484d; text-transform: uppercase; letter-spacing: 2px; }
117
-
118
- .output-box {
119
- border-left: 3px solid #8ff5ff;
120
- background: #171a1f;
121
- padding: 25px;
122
- font-family: 'Space Grotesk';
123
- font-size: 18px;
124
- line-height: 1.8;
125
- height: calc(100vh - 320px); /* Dynamically scales to viewport */
126
- min-height: 400px; /* Safe fallback */
127
- overflow-y: auto;
128
- white-space: pre-wrap;
129
- border-radius: 0 4px 4px 0;
130
- }
131
 
132
  .stButton>button { background-color: rgba(143, 245, 255, 0.05) !important; border: 1px solid #8ff5ff !important; color: #8ff5ff !important; width: 100%; padding: 12px; }
133
  .stButton>button:hover { background-color: #8ff5ff !important; color: #000 !important; }
@@ -149,9 +136,12 @@ def load_vision_engine():
149
  @st.cache_resource(show_spinner=False)
150
  def load_trocr_model(model_path):
151
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
152
  proc = TrOCRProcessor.from_pretrained(model_path)
153
 
154
  if os.path.exists(model_path):
 
155
  config = VisionEncoderDecoderConfig.from_pretrained(model_path)
156
  model = VisionEncoderDecoderModel(config)
157
  safe_path = os.path.join(model_path, "model.safetensors")
@@ -163,6 +153,7 @@ def load_trocr_model(model_path):
163
  else:
164
  model.load_state_dict(torch.load(bin_path, map_location="cpu", weights_only=True), strict=False)
165
  else:
 
166
  model = VisionEncoderDecoderModel.from_pretrained(model_path)
167
 
168
  # Push standard registered parameters/buffers to device
@@ -240,9 +231,13 @@ def main():
240
  run_scan_trigger = False
241
 
242
  with c_left:
 
243
  model_choice = st.selectbox("SELECT MODEL", ["V13 Specialist", "Microsoft Large"])
244
  st.markdown("<div style='height: 15px;'></div>", unsafe_allow_html=True)
245
- m_map = {"V13 Specialist": "./final_handwriting_model_v13", "Microsoft Large": "microsoft/trocr-large-handwritten"}
 
 
 
246
 
247
  if st.session_state.image_data is None:
248
  st.markdown("""
 
110
 
111
  /* ═══════════════════════════════════════════════════════════════ */
112
 
113
+ /* Stats & Output Box */
114
  .stat-card { background: #000; padding: 15px; border-radius: 4px; text-align: center; border: 1px solid rgba(143, 245, 255, 0.1); margin-bottom: 10px; }
115
  .stat-val { color: #8ff5ff; font-size: 24px; font-weight: 700; font-family: 'Space Grotesk'; }
116
  .stat-lbl { font-size: 9px; color: #46484d; text-transform: uppercase; letter-spacing: 2px; }
117
+ .output-box { border-left: 3px solid #8ff5ff; background: #171a1f; padding: 25px; font-family: 'Space Grotesk'; font-size: 18px; line-height: 1.8; height: 400px; overflow-y: auto; white-space: pre-wrap; border-radius: 0 4px 4px 0;}
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  .stButton>button { background-color: rgba(143, 245, 255, 0.05) !important; border: 1px solid #8ff5ff !important; color: #8ff5ff !important; width: 100%; padding: 12px; }
120
  .stButton>button:hover { background-color: #8ff5ff !important; color: #000 !important; }
 
136
  @st.cache_resource(show_spinner=False)
137
  def load_trocr_model(model_path):
138
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
139
+
140
+ # Hugging Face natively downloads the processor via the repo ID
141
  proc = TrOCRProcessor.from_pretrained(model_path)
142
 
143
  if os.path.exists(model_path):
144
+ # Local Loading Logic (Kept as a fallback just in case you run it locally again)
145
  config = VisionEncoderDecoderConfig.from_pretrained(model_path)
146
  model = VisionEncoderDecoderModel(config)
147
  safe_path = os.path.join(model_path, "model.safetensors")
 
153
  else:
154
  model.load_state_dict(torch.load(bin_path, map_location="cpu", weights_only=True), strict=False)
155
  else:
156
+ # Cloud Loading Logic: This natively pulls your model from the Hugging Face Hub
157
  model = VisionEncoderDecoderModel.from_pretrained(model_path)
158
 
159
  # Push standard registered parameters/buffers to device
 
231
  run_scan_trigger = False
232
 
233
  with c_left:
234
+ # ─── THE CLOUD REPOSITORY MAP ───
235
  model_choice = st.selectbox("SELECT MODEL", ["V13 Specialist", "Microsoft Large"])
236
  st.markdown("<div style='height: 15px;'></div>", unsafe_allow_html=True)
237
+ m_map = {
238
+ "V13 Specialist": "Hypernova823/ReadAI",
239
+ "Microsoft Large": "microsoft/trocr-large-handwritten"
240
+ }
241
 
242
  if st.session_state.image_data is None:
243
  st.markdown("""