Spaces:
Runtime error
Runtime error
BluechipTechnologiesAsia
commited on
Commit
•
9ed1ba5
1
Parent(s):
a0d6958
Upload 6 files
Browse files- app.py +39 -0
- dockerfile +11 -0
- requirements.txt +5 -0
- static/images/Arti.png +0 -0
- static/images/bluchip.png +0 -0
- templates/index.html +107 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import io
|
3 |
+
import base64
|
4 |
+
from diffusers import StableDiffusionPipeline
|
5 |
+
import torch
|
6 |
+
from flask import Flask, render_template, request, url_for
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
11 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
12 |
+
|
13 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
14 |
+
pipe = pipe.to(device)
|
15 |
+
pipe.enable_attention_slicing()
|
16 |
+
|
17 |
+
|
18 |
+
@app.route('/', methods=['GET', 'POST'])
|
19 |
+
def generate_image():
|
20 |
+
if request.method == 'POST':
|
21 |
+
prompt = request.form['prompt']
|
22 |
+
|
23 |
+
try:
|
24 |
+
image = pipe(prompt=prompt).images[0]
|
25 |
+
|
26 |
+
buffered = io.BytesIO()
|
27 |
+
image.save(buffered, format="PNG")
|
28 |
+
image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
29 |
+
image_data_uri = f"data:image/png;base64,{image_base64}"
|
30 |
+
|
31 |
+
return render_template('index.html', image_url=image_data_uri)
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
return render_template('index.html', error=str(e))
|
35 |
+
|
36 |
+
return render_template('index.html')
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
app.run(debug=True)
|
dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "app.app:app", "--host", "0.0.0.0", "--port", "7860"]
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
diffusers
|
3 |
+
torch
|
4 |
+
accelerate
|
5 |
+
transformers
|
static/images/Arti.png
ADDED
static/images/bluchip.png
ADDED
templates/index.html
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>ArtiVision</title>
|
5 |
+
<style>
|
6 |
+
body {
|
7 |
+
font-family: Arial, sans-serif;
|
8 |
+
margin: 0;
|
9 |
+
background: linear-gradient(45deg, #663399, #5B72FF);
|
10 |
+
min-height: 100vh;
|
11 |
+
display: flex;
|
12 |
+
align-items: center;
|
13 |
+
justify-content: center;
|
14 |
+
}
|
15 |
+
|
16 |
+
.top-nav-bar {
|
17 |
+
display: flex;
|
18 |
+
justify-content: space-between;
|
19 |
+
align-items: center;
|
20 |
+
padding: 10px 20px;
|
21 |
+
background-color: #fefefe;
|
22 |
+
|
23 |
+
position: fixed;
|
24 |
+
top: 0;
|
25 |
+
left: 0;
|
26 |
+
width: 100%;
|
27 |
+
z-index: 1;
|
28 |
+
}
|
29 |
+
|
30 |
+
.ArtiVision-logo {
|
31 |
+
display: flex;
|
32 |
+
justify-content: center;
|
33 |
+
align-items: center;
|
34 |
+
margin-top: auto;
|
35 |
+
}
|
36 |
+
|
37 |
+
.container {
|
38 |
+
max-width: 600px;
|
39 |
+
margin: 60px auto;
|
40 |
+
background-color: #fff;
|
41 |
+
border: 1px darkblue;
|
42 |
+
border-style: groove;
|
43 |
+
padding: 20px;
|
44 |
+
text-align: center;
|
45 |
+
}
|
46 |
+
|
47 |
+
header {
|
48 |
+
margin-bottom: 10px;
|
49 |
+
}
|
50 |
+
|
51 |
+
.form-container {
|
52 |
+
border-bottom: 1px solid #ddd;
|
53 |
+
padding-bottom: 20px;
|
54 |
+
}
|
55 |
+
|
56 |
+
.image-display img {
|
57 |
+
max-width: 100%;
|
58 |
+
height: auto;
|
59 |
+
margin-top: 20px;
|
60 |
+
}
|
61 |
+
|
62 |
+
button[type="submit"] {
|
63 |
+
background-color: #00008B;
|
64 |
+
color: white;
|
65 |
+
border-color: #00008B;
|
66 |
+
padding: 10px 20px;
|
67 |
+
border-radius: 5px;
|
68 |
+
cursor: pointer;
|
69 |
+
}
|
70 |
+
</style>
|
71 |
+
|
72 |
+
</head>
|
73 |
+
|
74 |
+
<body>
|
75 |
+
|
76 |
+
<div class="top-nav-bar">
|
77 |
+
<img src="{{ url_for('static', filename='images/bluechip.png')}}" alt="Bluchip Technologies Asia">
|
78 |
+
</div>
|
79 |
+
|
80 |
+
<div class="container">
|
81 |
+
<header>
|
82 |
+
<h1>ArtiVision AI Image Generator</h1>
|
83 |
+
</header>
|
84 |
+
|
85 |
+
<div class="ArtiVision-logo">
|
86 |
+
<img src="{{ url_for('static', filename='images/Arti.png')}}" alt="ArtiVision" style="height: 25%; width: 25%; border-radius: 80%;">
|
87 |
+
</div>
|
88 |
+
|
89 |
+
<div class="form-container">
|
90 |
+
<form method="POST">
|
91 |
+
<input type="text" name="prompt" placeholder="Enter your prompt">
|
92 |
+
<button type="submit">Generate Image</button>
|
93 |
+
</form>
|
94 |
+
</div>
|
95 |
+
|
96 |
+
<div class="image-display">
|
97 |
+
{% if image_url %}
|
98 |
+
<img src="{{ image_url }}" alt="Generated Image">
|
99 |
+
{% endif %}
|
100 |
+
</div>
|
101 |
+
|
102 |
+
{% if error %}
|
103 |
+
<p style="color: red;">Error: {{ error }}</p>
|
104 |
+
{% endif %}
|
105 |
+
</div>
|
106 |
+
</body>
|
107 |
+
</html>
|