koey811 commited on
Commit
0d85f9f
·
verified ·
1 Parent(s): c3bd007

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -14,20 +14,14 @@ except ImportError:
14
  st.success("PyTorch has been successfully installed!")
15
  import torch
16
 
17
- # Install Optimum library
18
- try:
19
- import optimum
20
- except ImportError:
21
- st.warning("Optimum library is not installed. Installing optimum...")
22
- import subprocess
23
- subprocess.run(["pip", "install", "optimum"])
24
- st.success("Optimum library has been successfully installed!")
25
- import optimum
26
-
27
  # Load the image captioning model
28
  caption_model = pipeline("image-to-text", model="unography/blip-large-long-cap")
29
 
30
- story_generator = pipeline("text-generation", model="TheBloke/storytime-13B-GPTQ")
 
 
 
 
31
 
32
  def generate_caption(image):
33
  # Generate the caption for the uploaded image
@@ -36,7 +30,7 @@ def generate_caption(image):
36
 
37
  def generate_story(caption):
38
  # Generate the story based on the caption using the GPT-2 model
39
- prompt = f"Write a short, simple children's story inspired by the image of {caption}. Here's the story:\n\n"
40
  story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
41
 
42
  # Extract the story text from the generated output
 
14
  st.success("PyTorch has been successfully installed!")
15
  import torch
16
 
 
 
 
 
 
 
 
 
 
 
17
  # Load the image captioning model
18
  caption_model = pipeline("image-to-text", model="unography/blip-large-long-cap")
19
 
20
+ #story_generator = pipeline("text-generation", model="distilbert/distilgpt2")
21
+
22
+ #story_generator = pipeline("text-generation", model="isarth/distill_gpt2_story_generator")
23
+
24
+ story_generator = pipeline("text-generation", model="mosaicml/mpt-7b-storywriter", trust_remote_code=True)
25
 
26
  def generate_caption(image):
27
  # Generate the caption for the uploaded image
 
30
 
31
  def generate_story(caption):
32
  # Generate the story based on the caption using the GPT-2 model
33
+ prompt = f"Write a short, simple children's fairytale story with reference of the image of {caption}. Here's the story:\n\n"
34
  story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
35
 
36
  # Extract the story text from the generated output