jjz5463 commited on
Commit
868e527
·
1 Parent(s): 7907d0c
Experiments/Baseline/GUI.py CHANGED
@@ -4,6 +4,7 @@ import json
4
  from PIL import Image
5
  from google.oauth2 import service_account
6
  from baseline_utils import detect_text_in_image, summarize_diary_text, analyze_writer_image, generate_comic_book
 
7
 
8
  # Load secrets
9
  openai_api_key = st.secrets["general"]["openai_api_key"]
@@ -24,13 +25,16 @@ uploaded_writer_image = st.file_uploader("Upload a photo of the writer", type=["
24
  if uploaded_diary and uploaded_writer_image:
25
  st.write("Analyzing your diary and writer...")
26
 
27
- # Read the uploaded images
28
  diary_image = Image.open(uploaded_diary)
29
  writer_image = Image.open(uploaded_writer_image)
30
 
31
- # Save uploaded images temporarily (Streamlit does this automatically with file objects)
32
- diary_image_path = uploaded_diary.name
33
- writer_image_path = uploaded_writer_image.name
 
 
 
34
 
35
  # Detect text from the diary image
36
  google_credentials = get_google_credentials()
@@ -46,4 +50,11 @@ if uploaded_diary and uploaded_writer_image:
46
  st.write("Generating comic book images...")
47
  generate_comic_book(summarized_text, writer_summary, num_pages=5)
48
 
49
- st.write("Comic book generated successfully!")
 
 
 
 
 
 
 
 
4
  from PIL import Image
5
  from google.oauth2 import service_account
6
  from baseline_utils import detect_text_in_image, summarize_diary_text, analyze_writer_image, generate_comic_book
7
+ import glob
8
 
9
  # Load secrets
10
  openai_api_key = st.secrets["general"]["openai_api_key"]
 
25
  if uploaded_diary and uploaded_writer_image:
26
  st.write("Analyzing your diary and writer...")
27
 
28
+ # Read the uploaded images using file-like objects
29
  diary_image = Image.open(uploaded_diary)
30
  writer_image = Image.open(uploaded_writer_image)
31
 
32
+ # Save the file-like objects as image files (optional if needed)
33
+ diary_image_path = "temp_diary_image.png"
34
+ writer_image_path = "temp_writer_image.png"
35
+
36
+ diary_image.save(diary_image_path)
37
+ writer_image.save(writer_image_path)
38
 
39
  # Detect text from the diary image
40
  google_credentials = get_google_credentials()
 
50
  st.write("Generating comic book images...")
51
  generate_comic_book(summarized_text, writer_summary, num_pages=5)
52
 
53
+ st.write("Comic book generated successfully!")
54
+
55
+ # Assuming generated images are saved as 'comic_book/page_1.png', 'comic_book/page_2.png', etc.
56
+ image_files = sorted(glob.glob("comic_book/page_*.png")) # Find all the generated comic book pages
57
+
58
+ for image_file in image_files:
59
+ # Display each comic book page
60
+ st.image(image_file, caption=image_file.split('/')[-1], use_column_width=True)
Experiments/Baseline/baseline_utils.py CHANGED
@@ -9,9 +9,7 @@ import os
9
 
10
  # Utilize the Google Cloud Vision API to recognize text in the
11
  # input input_images (diary input_images), https://cloud.google.com/vision.
12
- def detect_text_in_image(image_path, credentials_path):
13
- # Load the service account key from the credentials JSON file
14
- credentials = service_account.Credentials.from_service_account_file(credentials_path)
15
 
16
  # Create a Vision API client using the credentials
17
  client = vision.ImageAnnotatorClient(credentials=credentials)
 
9
 
10
  # Utilize the Google Cloud Vision API to recognize text in the
11
  # input input_images (diary input_images), https://cloud.google.com/vision.
12
+ def detect_text_in_image(image_path, credentials):
 
 
13
 
14
  # Create a Vision API client using the credentials
15
  client = vision.ImageAnnotatorClient(credentials=credentials)
requirements.txt CHANGED
@@ -3,4 +3,5 @@ google-cloud-vision
3
  google-auth
4
  google-generativeai
5
  diffusers
6
- torch
 
 
3
  google-auth
4
  google-generativeai
5
  diffusers
6
+ torch
7
+ streamlit