gary109 fffiloni commited on
Commit
930f09b
·
0 Parent(s):

Duplicate from fffiloni/Image-to-Story

Browse files

Co-authored-by: Sylvain Filoni <[email protected]>

Files changed (7) hide show
  1. .gitattributes +37 -0
  2. README.md +13 -0
  3. app.py +79 -0
  4. examples/blank.md +0 -0
  5. examples/crabby.png +3 -0
  6. examples/hopper.jpeg +0 -0
  7. requirements.txt +0 -0
.gitattributes ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/3813193B-7B9F-41C0-AA90-09A52F643629.png filter=lfs diff=lfs merge=lfs -text
37
+ examples/crabby.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Image To Story
3
+ emoji: 👁
4
+ colorFrom: pink
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.39.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: fffiloni/Image-to-Story
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import os
4
+ hf_token = os.environ.get('HF_TOKEN')
5
+ from gradio_client import Client
6
+ client = Client("https://fffiloni-test-llama-api.hf.space/", hf_token=hf_token)
7
+
8
+ clipi_client = Client("https://fffiloni-clip-interrogator-2.hf.space/")
9
+
10
+ def get_text_after_colon(input_text):
11
+ # Find the first occurrence of ":"
12
+ colon_index = input_text.find(":")
13
+
14
+ # Check if ":" exists in the input_text
15
+ if colon_index != -1:
16
+ # Extract the text after the colon
17
+ result_text = input_text[colon_index + 1:].strip()
18
+ return result_text
19
+ else:
20
+ # Return the original text if ":" is not found
21
+ return input_text
22
+
23
+ def infer(image_input):
24
+
25
+ clipi_result = clipi_client.predict(
26
+ image_input, # str (filepath or URL to image) in 'parameter_3' Image component
27
+ "best", # str in 'Select mode' Radio component
28
+ 4, # int | float (numeric value between 2 and 24) in 'best mode max flavors' Slider component
29
+ api_name="/clipi2"
30
+ )
31
+ print(clipi_result)
32
+
33
+
34
+ llama_q = f"""
35
+ I'll give you a simple image caption, from i want you to provide a story that would fit well with the image:
36
+ '{clipi_result[0]}'
37
+
38
+ """
39
+
40
+ result = client.predict(
41
+ llama_q, # str in 'Message' Textbox component
42
+ api_name="/predict"
43
+ )
44
+
45
+ print(f"Llama2 result: {result}")
46
+
47
+ result = get_text_after_colon(result)
48
+
49
+ return result
50
+
51
+ css="""
52
+ #col-container {max-width: 910px; margin-left: auto; margin-right: auto;}
53
+ a {text-decoration-line: underline; font-weight: 600;}
54
+ """
55
+
56
+ with gr.Blocks(css=css) as demo:
57
+ with gr.Column(elem_id="col-container"):
58
+ gr.Markdown(
59
+ """
60
+ <h1 style="text-align: center">Image to Story</h1>
61
+ <p style="text-align: center">Upload an image, get a story made by Llama2 !</p>
62
+ """
63
+ )
64
+ with gr.Row():
65
+ with gr.Column():
66
+ image_in = gr.Image(label="Image input", type="filepath")
67
+ submit_btn = gr.Button('Tell me a story')
68
+ with gr.Column():
69
+ #caption = gr.Textbox(label="Generated Caption")
70
+ story = gr.Textbox(label="generated Story")
71
+ gr.Examples(examples=[["./examples/crabby.png"],["./examples/hopper.jpeg"]],
72
+ fn=infer,
73
+ inputs=[image_in],
74
+ outputs=[story],
75
+ cache_examples=True
76
+ )
77
+ submit_btn.click(fn=infer, inputs=[image_in], outputs=[story])
78
+
79
+ demo.queue(max_size=12).launch()
examples/blank.md ADDED
File without changes
examples/crabby.png ADDED

Git LFS Details

  • SHA256: 7c09cf04b6c777af3b1b581ce8001416c80372cc4d48e374dd0dd67beb680467
  • Pointer size: 132 Bytes
  • Size of remote file: 1.58 MB
examples/hopper.jpeg ADDED
requirements.txt ADDED
File without changes