Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoProcessor
|
3 |
+
|
4 |
+
# Load the model and processor from HF Hub
|
5 |
+
model_name = "NickoSELI/blip2-indian-food-captioning-private-checkopt-mock1"
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True)
|
7 |
+
processor = AutoProcessor.from_pretrained(model_name, use_auth_token=True)
|
8 |
+
|
9 |
+
# Define a prediction function
|
10 |
+
def predict(image):
|
11 |
+
inputs = processor(images=image, return_tensors="pt")
|
12 |
+
outputs = model.generate(**inputs)
|
13 |
+
caption = processor.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return caption
|
15 |
+
|
16 |
+
# Create a Gradio interface
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=predict,
|
19 |
+
inputs=gr.inputs.Image(type="pil"),
|
20 |
+
outputs="text",
|
21 |
+
title="Indian Food Captioning Model"
|
22 |
+
)
|
23 |
+
|
24 |
+
# Launch the interface
|
25 |
+
if __name__ == "__main__":
|
26 |
+
interface.launch()
|