fffiloni commited on
Commit
5f7a8ac
·
verified ·
1 Parent(s): ac7ec65
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -21,6 +21,14 @@ clipi_client = Client("https://fffiloni-clip-interrogator-2.hf.space/")
21
 
22
  @spaces.GPU
23
  def llama_gen_story(prompt):
 
 
 
 
 
 
 
 
24
 
25
  instruction = """[INST] <<SYS>>\nYou are a storyteller. You'll be given an image description and some keyword about the image.
26
  For that given you'll be asked to generate a story that you think could fit very well with the image provided.
@@ -52,6 +60,20 @@ def get_text_after_colon(input_text):
52
  return input_text
53
 
54
  def infer(image_input, audience):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  gr.Info('Calling CLIP Interrogator ...')
56
 
57
  clipi_result = clipi_client.predict(
@@ -121,4 +143,4 @@ with gr.Blocks(css=css) as demo:
121
 
122
  submit_btn.click(fn=infer, inputs=[image_in, audience], outputs=[story])
123
 
124
- demo.queue(max_size=12).launch(ssr_mode=False)
 
21
 
22
  @spaces.GPU
23
  def llama_gen_story(prompt):
24
+ """Generate a fictional story using the LLaMA 2 model based on a prompt.
25
+
26
+ Args:
27
+ prompt: A string prompt containing an image description and story generation instructions.
28
+
29
+ Returns:
30
+ A generated fictional story string with special formatting and tokens removed.
31
+ """
32
 
33
  instruction = """[INST] <<SYS>>\nYou are a storyteller. You'll be given an image description and some keyword about the image.
34
  For that given you'll be asked to generate a story that you think could fit very well with the image provided.
 
60
  return input_text
61
 
62
  def infer(image_input, audience):
63
+ """Generate a fictional story based on an image using CLIP Interrogator and LLaMA2.
64
+
65
+ Args:
66
+ image_input: A file path to the input image to analyze.
67
+ audience: A string indicating the target audience, such as 'Children' or 'Adult'.
68
+
69
+ Returns:
70
+ A formatted, multi-paragraph fictional story string related to the image content.
71
+
72
+ Steps:
73
+ 1. Use the CLIP Interrogator model to generate a semantic caption from the image.
74
+ 2. Format a prompt asking the LLaMA2 model to write a story based on the caption.
75
+ 3. Clean and format the story output for readability.
76
+ """
77
  gr.Info('Calling CLIP Interrogator ...')
78
 
79
  clipi_result = clipi_client.predict(
 
143
 
144
  submit_btn.click(fn=infer, inputs=[image_in, audience], outputs=[story])
145
 
146
+ demo.queue(max_size=12).launch(ssr_mode=False, mcp_server=True)