File size: 2,633 Bytes
de2fc55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import gradio as gr
from transformers import AutoProcessor, AutoModelForCausalLM
from PIL import Image

# Load the model and processor
processor = AutoProcessor.from_pretrained("Aman1212222/Image_to_ballad")
model = AutoModelForCausalLM.from_pretrained("Aman1212222/Image_to_ballad")

# Prediction function
def generate_caption(image):
    # Process the image
    inputs = processor(images=image, return_tensors="pt")
    pixel_values = inputs.pixel_values

    # Generate the caption
    generated_ids = model.generate(pixel_values=pixel_values, max_length=100)
    generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
    
    return generated_caption

# Enhanced CSS for WOW factor
css_style = """
body {
    background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.gradio-container {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    color: white;
    text-align: center;
    width: 500px;
}

.gradio-title {
    font-size: 36px;
    font-weight: bold;
    letter-spacing: 1px;
    margin-bottom: 20px;
    color: #ffffff;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
}

.gradio-description {
    font-size: 18px;
    margin-bottom: 30px;
    color: #ffffff;
    text-shadow: 1px 1px 5px rgba(0, 0, 0, 0.4);
}

.gradio-input, .gradio-output {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    transition: transform 0.3s ease;
}

.gradio-input:hover, .gradio-output:hover {
    transform: scale(1.05);
}

.gr-button {
    background-color: #ff5733;
    color: white;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.3s ease;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.gr-button:hover {
    background-color: #ff2e00;
    transform: translateY(-4px);
}

footer {
    display: none !important;
}
"""

# Create Gradio Interface
interface = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="✨ Image to Ballad Generator ✨",
    description="Upload an image, and we'll generate a ballad for it with our AI-powered model!",
    theme="default",
    css=css_style
)

# Launch the interface with a public link
interface.launch(share=True)