erayman09 commited on
Commit
50c9935
·
verified ·
1 Parent(s): 1d49cb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -11,10 +11,12 @@ story_tokenizer = AutoTokenizer.from_pretrained(story_model_name)
11
  story_model = AutoModelForCausalLM.from_pretrained(story_model_name)
12
 
13
  # Function to extract text description from an image
14
- def extract_description(image_path):
15
  try:
 
 
16
  # Use the OCR model to extract a caption/description from the image
17
- result = ocr_model(Image.open(image_path))
18
  return result[0]["generated_text"]
19
  except Exception as e:
20
  return f"Error extracting description: {e}"
@@ -39,7 +41,7 @@ def create_story(image):
39
  # Step 1: Extract a description from the image
40
  description = extract_description(image)
41
  if not description or "Error" in description:
42
- return description, None
43
 
44
  # Step 2: Generate a story from the extracted description
45
  story = generate_story(description)
 
11
  story_model = AutoModelForCausalLM.from_pretrained(story_model_name)
12
 
13
  # Function to extract text description from an image
14
+ def extract_description(image_array):
15
  try:
16
+ # Convert the NumPy array to a PIL image
17
+ image = Image.fromarray(image_array)
18
  # Use the OCR model to extract a caption/description from the image
19
+ result = ocr_model(image)
20
  return result[0]["generated_text"]
21
  except Exception as e:
22
  return f"Error extracting description: {e}"
 
41
  # Step 1: Extract a description from the image
42
  description = extract_description(image)
43
  if not description or "Error" in description:
44
+ return description
45
 
46
  # Step 2: Generate a story from the extracted description
47
  story = generate_story(description)