Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load the model and processor
|
6 |
+
processor = AutoProcessor.from_pretrained("Aman1212222/Image_to_ballad")
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("Aman1212222/Image_to_ballad")
|
8 |
+
|
9 |
+
# Prediction function
|
10 |
+
def generate_caption(image):
|
11 |
+
# Process the image
|
12 |
+
inputs = processor(images=image, return_tensors="pt")
|
13 |
+
pixel_values = inputs.pixel_values
|
14 |
+
|
15 |
+
# Generate the caption
|
16 |
+
generated_ids = model.generate(pixel_values=pixel_values, max_length=100)
|
17 |
+
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
18 |
+
|
19 |
+
return generated_caption
|
20 |
+
|
21 |
+
# Enhanced CSS for WOW factor
|
22 |
+
css_style = """
|
23 |
+
body {
|
24 |
+
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
|
25 |
+
font-family: 'Roboto', sans-serif;
|
26 |
+
margin: 0;
|
27 |
+
padding: 0;
|
28 |
+
display: flex;
|
29 |
+
justify-content: center;
|
30 |
+
align-items: center;
|
31 |
+
height: 100vh;
|
32 |
+
}
|
33 |
+
|
34 |
+
.gradio-container {
|
35 |
+
backdrop-filter: blur(10px);
|
36 |
+
background: rgba(255, 255, 255, 0.1);
|
37 |
+
border-radius: 15px;
|
38 |
+
padding: 30px;
|
39 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
40 |
+
color: white;
|
41 |
+
text-align: center;
|
42 |
+
width: 500px;
|
43 |
+
}
|
44 |
+
|
45 |
+
.gradio-title {
|
46 |
+
font-size: 36px;
|
47 |
+
font-weight: bold;
|
48 |
+
letter-spacing: 1px;
|
49 |
+
margin-bottom: 20px;
|
50 |
+
color: #ffffff;
|
51 |
+
text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
|
52 |
+
}
|
53 |
+
|
54 |
+
.gradio-description {
|
55 |
+
font-size: 18px;
|
56 |
+
margin-bottom: 30px;
|
57 |
+
color: #ffffff;
|
58 |
+
text-shadow: 1px 1px 5px rgba(0, 0, 0, 0.4);
|
59 |
+
}
|
60 |
+
|
61 |
+
.gradio-input, .gradio-output {
|
62 |
+
background: rgba(255, 255, 255, 0.2);
|
63 |
+
border: none;
|
64 |
+
border-radius: 10px;
|
65 |
+
padding: 15px;
|
66 |
+
margin-bottom: 20px;
|
67 |
+
transition: transform 0.3s ease;
|
68 |
+
}
|
69 |
+
|
70 |
+
.gradio-input:hover, .gradio-output:hover {
|
71 |
+
transform: scale(1.05);
|
72 |
+
}
|
73 |
+
|
74 |
+
.gr-button {
|
75 |
+
background-color: #ff5733;
|
76 |
+
color: white;
|
77 |
+
border-radius: 12px;
|
78 |
+
padding: 12px 24px;
|
79 |
+
font-size: 18px;
|
80 |
+
font-weight: bold;
|
81 |
+
cursor: pointer;
|
82 |
+
transition: background-color 0.3s ease, transform 0.3s ease;
|
83 |
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
|
84 |
+
}
|
85 |
+
|
86 |
+
.gr-button:hover {
|
87 |
+
background-color: #ff2e00;
|
88 |
+
transform: translateY(-4px);
|
89 |
+
}
|
90 |
+
|
91 |
+
footer {
|
92 |
+
display: none !important;
|
93 |
+
}
|
94 |
+
"""
|
95 |
+
|
96 |
+
# Create Gradio Interface
|
97 |
+
interface = gr.Interface(
|
98 |
+
fn=generate_caption,
|
99 |
+
inputs=gr.Image(type="pil"),
|
100 |
+
outputs="text",
|
101 |
+
title="✨ Image to Ballad Generator ✨",
|
102 |
+
description="Upload an image, and we'll generate a ballad for it with our AI-powered model!",
|
103 |
+
theme="default",
|
104 |
+
css=css_style
|
105 |
+
)
|
106 |
+
|
107 |
+
# Launch the interface with a public link
|
108 |
+
interface.launch(share=True)
|