File size: 1,151 Bytes
b1385de
9f71c5e
b1385de
9f71c5e
b1385de
 
9f71c5e
b1385de
 
 
 
 
 
 
 
 
 
 
9f71c5e
 
 
 
 
 
 
 
 
 
 
b1385de
 
9f71c5e
 
 
 
 
b1385de
 
9f71c5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from transformers import BlipProcessor, BlipForConditionalGeneration
import gradio as gr

# Load the token from the environment
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")

# Load the model and processor with the token
processor = BlipProcessor.from_pretrained(
    "quadranttechnologies/Imageclassification",
    use_auth_token=HUGGINGFACE_TOKEN
)
model = BlipForConditionalGeneration.from_pretrained(
    "quadranttechnologies/Imageclassification",
    use_auth_token=HUGGINGFACE_TOKEN
)

# Define your Gradio interface and logic as before
def generate_caption(image):
    try:
        inputs = processor(image, return_tensors="pt")
        outputs = model.generate(**inputs)
        caption = processor.decode(outputs[0], skip_special_tokens=True)
        return caption
    except Exception as e:
        return f"Error generating caption: {e}"

interface = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Image Captioning Model",
    description="Upload an image to receive a caption generated by the model."
)

if __name__ == "__main__":
    interface.launch(share=True)