File size: 840 Bytes
a5dda79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoProcessor

# Load the model and processor from HF Hub
model_name = "NickoSELI/blip2-indian-food-captioning-private-checkopt-mock1"
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True)
processor = AutoProcessor.from_pretrained(model_name, use_auth_token=True)

# Define a prediction function
def predict(image):
    inputs = processor(images=image, return_tensors="pt")
    outputs = model.generate(**inputs)
    caption = processor.decode(outputs[0], skip_special_tokens=True)
    return caption

# Create a Gradio interface
interface = gr.Interface(
    fn=predict,
    inputs=gr.inputs.Image(type="pil"),
    outputs="text",
    title="Indian Food Captioning Model"
)

# Launch the interface
if __name__ == "__main__":
    interface.launch()