Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +7 -4
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,6 +4,9 @@ from PIL import Image
|
|
| 4 |
import requests
|
| 5 |
import traceback
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
class Image2Text:
|
| 8 |
def __init__(self):
|
| 9 |
# Load the GIT coco model
|
|
@@ -188,7 +191,7 @@ class Social_Media_Captioner:
|
|
| 188 |
self.model_loaded = False
|
| 189 |
|
| 190 |
|
| 191 |
-
def inference(self, input_text: str, use_cached=True, cache_generation=True):
|
| 192 |
if not self.model_loaded:
|
| 193 |
raise Exception("Model not loaded")
|
| 194 |
|
|
@@ -230,7 +233,7 @@ class Social_Media_Captioner:
|
|
| 230 |
raise Exception("Enter a valid input text to generate a valid prompt")
|
| 231 |
|
| 232 |
return f"""
|
| 233 |
-
Convert the given image description to
|
| 234 |
Description: {input_text}
|
| 235 |
Caption:
|
| 236 |
""".strip()
|
|
@@ -279,7 +282,7 @@ class Captions:
|
|
| 279 |
image_description = self.image_to_text._generate_description(image, max_length=max_length_GIT)
|
| 280 |
captions = self.LLM.inference(image_description, use_cached=use_cached_LLM, cache_generation=cache_generation_LLM)
|
| 281 |
return captions
|
| 282 |
-
|
| 283 |
caption_generator = Captions()
|
| 284 |
|
| 285 |
import gradio as gr
|
|
@@ -293,4 +296,4 @@ iface = gr.Interface(
|
|
| 293 |
outputs=gr.outputs.Textbox(label="Caption")
|
| 294 |
)
|
| 295 |
|
| 296 |
-
iface.launch()
|
|
|
|
| 4 |
import requests
|
| 5 |
import traceback
|
| 6 |
|
| 7 |
+
from huggingface_hub import login
|
| 8 |
+
login(token=HF_TOKEN)
|
| 9 |
+
|
| 10 |
class Image2Text:
|
| 11 |
def __init__(self):
|
| 12 |
# Load the GIT coco model
|
|
|
|
| 191 |
self.model_loaded = False
|
| 192 |
|
| 193 |
|
| 194 |
+
def inference(self, input_text: str, use_cached=True, cache_generation=True) -> str | None:
|
| 195 |
if not self.model_loaded:
|
| 196 |
raise Exception("Model not loaded")
|
| 197 |
|
|
|
|
| 233 |
raise Exception("Enter a valid input text to generate a valid prompt")
|
| 234 |
|
| 235 |
return f"""
|
| 236 |
+
Convert the given image description to a appropriate metaphoric caption
|
| 237 |
Description: {input_text}
|
| 238 |
Caption:
|
| 239 |
""".strip()
|
|
|
|
| 282 |
image_description = self.image_to_text._generate_description(image, max_length=max_length_GIT)
|
| 283 |
captions = self.LLM.inference(image_description, use_cached=use_cached_LLM, cache_generation=cache_generation_LLM)
|
| 284 |
return captions
|
| 285 |
+
|
| 286 |
caption_generator = Captions()
|
| 287 |
|
| 288 |
import gradio as gr
|
|
|
|
| 296 |
outputs=gr.outputs.Textbox(label="Caption")
|
| 297 |
)
|
| 298 |
|
| 299 |
+
iface.launch(share=True)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
evaluate
|
| 2 |
jiwer
|
| 3 |
huggingface_hub @ git+https://github.com/huggingface/huggingface_hub.git
|
| 4 |
-
gradio==3.
|
| 5 |
bitsandbytes
|
| 6 |
transformers @ git+https://github.com/huggingface/transformers.git
|
| 7 |
peft @ git+https://github.com/huggingface/peft.git
|
|
@@ -11,3 +11,4 @@ safetensors
|
|
| 11 |
torch
|
| 12 |
xformers
|
| 13 |
datasets
|
|
|
|
|
|
| 1 |
evaluate
|
| 2 |
jiwer
|
| 3 |
huggingface_hub @ git+https://github.com/huggingface/huggingface_hub.git
|
| 4 |
+
gradio==3.36.0
|
| 5 |
bitsandbytes
|
| 6 |
transformers @ git+https://github.com/huggingface/transformers.git
|
| 7 |
peft @ git+https://github.com/huggingface/peft.git
|
|
|
|
| 11 |
torch
|
| 12 |
xformers
|
| 13 |
datasets
|
| 14 |
+
stable-diffusion
|