Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import zipfile
|
|
| 8 |
import re
|
| 9 |
import logging
|
| 10 |
import asyncio
|
|
|
|
| 11 |
from io import BytesIO
|
| 12 |
from datetime import datetime
|
| 13 |
import pytz
|
|
@@ -19,6 +20,7 @@ import pandas as pd
|
|
| 19 |
import torch
|
| 20 |
import fitz
|
| 21 |
import requests
|
|
|
|
| 22 |
from PIL import Image
|
| 23 |
from diffusers import StableDiffusionPipeline
|
| 24 |
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
|
|
@@ -272,7 +274,7 @@ def process_image_with_prompt(image, prompt, model="o3-mini-high"):
|
|
| 272 |
except Exception as e:
|
| 273 |
return f"Error processing image with GPT: {str(e)}"
|
| 274 |
|
| 275 |
-
# --- Sidebar Setup
|
| 276 |
st.sidebar.subheader("Gallery Settings")
|
| 277 |
if 'gallery_size' not in st.session_state:
|
| 278 |
st.session_state['gallery_size'] = 2 # Default value
|
|
@@ -288,7 +290,6 @@ def update_gallery():
|
|
| 288 |
if all_files:
|
| 289 |
st.sidebar.subheader("Asset Gallery 📸📖")
|
| 290 |
cols = st.sidebar.columns(2)
|
| 291 |
-
# Use the stored gallery size from session state
|
| 292 |
for idx, file in enumerate(all_files[:st.session_state['gallery_size']]):
|
| 293 |
with cols[idx % 2]:
|
| 294 |
st.session_state['unique_counter'] += 1
|
|
@@ -315,10 +316,9 @@ def update_gallery():
|
|
| 315 |
st.sidebar.success(f"Asset {os.path.basename(file)} vaporized! 💨")
|
| 316 |
st.rerun()
|
| 317 |
|
| 318 |
-
# Call update_gallery() once initially
|
| 319 |
update_gallery()
|
| 320 |
|
| 321 |
-
|
| 322 |
# --- Sidebar Logs & History ---
|
| 323 |
st.sidebar.subheader("Action Logs 📜")
|
| 324 |
with st.sidebar:
|
|
@@ -329,7 +329,7 @@ with st.sidebar:
|
|
| 329 |
for entry in st.session_state['history']:
|
| 330 |
st.write(entry)
|
| 331 |
|
| 332 |
-
# --- Create Tabs
|
| 333 |
tabs = st.tabs([
|
| 334 |
"Camera Snap 📷",
|
| 335 |
"Download PDFs 📥",
|
|
@@ -342,7 +342,7 @@ tabs = st.tabs([
|
|
| 342 |
])
|
| 343 |
(tab_camera, tab_download, tab_ocr, tab_build, tab_imggen, tab_pdf_process, tab_image_process, tab_md_gallery) = tabs
|
| 344 |
|
| 345 |
-
# === Tab: Camera Snap
|
| 346 |
with tab_camera:
|
| 347 |
st.header("Camera Snap 📷")
|
| 348 |
st.subheader("Single Capture")
|
|
@@ -378,7 +378,7 @@ with tab_camera:
|
|
| 378 |
logger.info(f"Saved snapshot from Camera 1: {filename}")
|
| 379 |
update_gallery()
|
| 380 |
|
| 381 |
-
# === Tab: Download PDFs
|
| 382 |
with tab_download:
|
| 383 |
st.header("Download PDFs 📥")
|
| 384 |
if st.button("Examples 📚"):
|
|
@@ -439,7 +439,7 @@ with tab_download:
|
|
| 439 |
else:
|
| 440 |
st.warning("No PDFs selected for snapshotting! Check some boxes in the sidebar.")
|
| 441 |
|
| 442 |
-
# === Tab: Test OCR
|
| 443 |
with tab_ocr:
|
| 444 |
st.header("Test OCR 🔍")
|
| 445 |
all_files = get_gallery_files()
|
|
@@ -505,7 +505,7 @@ with tab_ocr:
|
|
| 505 |
else:
|
| 506 |
st.warning("No assets in gallery yet. Use Camera Snap or Download PDFs!")
|
| 507 |
|
| 508 |
-
# === Tab: Build Titan
|
| 509 |
with tab_build:
|
| 510 |
st.header("Build Titan 🌱")
|
| 511 |
model_type = st.selectbox("Model Type", ["Causal LM", "Diffusion"], key="build_type")
|
|
@@ -529,7 +529,7 @@ with tab_build:
|
|
| 529 |
st.success(f"Model downloaded and saved to {config.model_path}! 🎉")
|
| 530 |
st.rerun()
|
| 531 |
|
| 532 |
-
# === Tab: Test Image Gen
|
| 533 |
with tab_imggen:
|
| 534 |
st.header("Test Image Gen 🎨")
|
| 535 |
all_files = get_gallery_files()
|
|
@@ -693,4 +693,4 @@ with tab_md_gallery:
|
|
| 693 |
else:
|
| 694 |
st.warning("No MD files selected.")
|
| 695 |
else:
|
| 696 |
-
st.warning("No MD files found.")
|
|
|
|
| 8 |
import re
|
| 9 |
import logging
|
| 10 |
import asyncio
|
| 11 |
+
import random # Added for ModelBuilder jokes
|
| 12 |
from io import BytesIO
|
| 13 |
from datetime import datetime
|
| 14 |
import pytz
|
|
|
|
| 20 |
import torch
|
| 21 |
import fitz
|
| 22 |
import requests
|
| 23 |
+
import aiofiles # Added for async file operations
|
| 24 |
from PIL import Image
|
| 25 |
from diffusers import StableDiffusionPipeline
|
| 26 |
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
|
|
|
|
| 274 |
except Exception as e:
|
| 275 |
return f"Error processing image with GPT: {str(e)}"
|
| 276 |
|
| 277 |
+
# --- Sidebar Setup ---
|
| 278 |
st.sidebar.subheader("Gallery Settings")
|
| 279 |
if 'gallery_size' not in st.session_state:
|
| 280 |
st.session_state['gallery_size'] = 2 # Default value
|
|
|
|
| 290 |
if all_files:
|
| 291 |
st.sidebar.subheader("Asset Gallery 📸📖")
|
| 292 |
cols = st.sidebar.columns(2)
|
|
|
|
| 293 |
for idx, file in enumerate(all_files[:st.session_state['gallery_size']]):
|
| 294 |
with cols[idx % 2]:
|
| 295 |
st.session_state['unique_counter'] += 1
|
|
|
|
| 316 |
st.sidebar.success(f"Asset {os.path.basename(file)} vaporized! 💨")
|
| 317 |
st.rerun()
|
| 318 |
|
| 319 |
+
# Call update_gallery() once initially
|
| 320 |
update_gallery()
|
| 321 |
|
|
|
|
| 322 |
# --- Sidebar Logs & History ---
|
| 323 |
st.sidebar.subheader("Action Logs 📜")
|
| 324 |
with st.sidebar:
|
|
|
|
| 329 |
for entry in st.session_state['history']:
|
| 330 |
st.write(entry)
|
| 331 |
|
| 332 |
+
# --- Create Tabs ---
|
| 333 |
tabs = st.tabs([
|
| 334 |
"Camera Snap 📷",
|
| 335 |
"Download PDFs 📥",
|
|
|
|
| 342 |
])
|
| 343 |
(tab_camera, tab_download, tab_ocr, tab_build, tab_imggen, tab_pdf_process, tab_image_process, tab_md_gallery) = tabs
|
| 344 |
|
| 345 |
+
# === Tab: Camera Snap ===
|
| 346 |
with tab_camera:
|
| 347 |
st.header("Camera Snap 📷")
|
| 348 |
st.subheader("Single Capture")
|
|
|
|
| 378 |
logger.info(f"Saved snapshot from Camera 1: {filename}")
|
| 379 |
update_gallery()
|
| 380 |
|
| 381 |
+
# === Tab: Download PDFs ===
|
| 382 |
with tab_download:
|
| 383 |
st.header("Download PDFs 📥")
|
| 384 |
if st.button("Examples 📚"):
|
|
|
|
| 439 |
else:
|
| 440 |
st.warning("No PDFs selected for snapshotting! Check some boxes in the sidebar.")
|
| 441 |
|
| 442 |
+
# === Tab: Test OCR ===
|
| 443 |
with tab_ocr:
|
| 444 |
st.header("Test OCR 🔍")
|
| 445 |
all_files = get_gallery_files()
|
|
|
|
| 505 |
else:
|
| 506 |
st.warning("No assets in gallery yet. Use Camera Snap or Download PDFs!")
|
| 507 |
|
| 508 |
+
# === Tab: Build Titan ===
|
| 509 |
with tab_build:
|
| 510 |
st.header("Build Titan 🌱")
|
| 511 |
model_type = st.selectbox("Model Type", ["Causal LM", "Diffusion"], key="build_type")
|
|
|
|
| 529 |
st.success(f"Model downloaded and saved to {config.model_path}! 🎉")
|
| 530 |
st.rerun()
|
| 531 |
|
| 532 |
+
# === Tab: Test Image Gen ===
|
| 533 |
with tab_imggen:
|
| 534 |
st.header("Test Image Gen 🎨")
|
| 535 |
all_files = get_gallery_files()
|
|
|
|
| 693 |
else:
|
| 694 |
st.warning("No MD files selected.")
|
| 695 |
else:
|
| 696 |
+
st.warning("No MD files found.")
|