pushpendra.parmar commited on
Commit
71ed633
·
0 Parent(s):

Initial commit

Browse files
Files changed (6) hide show
  1. .env +1 -0
  2. README.md +9 -0
  3. app.py +124 -0
  4. index.html +141 -0
  5. requirements.txt +2 -0
  6. temp_image.jpg +0 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ export GOOGLE_API_KEY=AIzaSyCFUjGZANPs5kLFN6BUfpwP9xbDwUCwNvo
README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ title: Gemini UI Generator
2
+ emoji: 💻
3
+ colorFrom: blue
4
+ colorTo: gray
5
+ sdk: streamlit
6
+ app_file: app.py
7
+ pinned: false
8
+ license: apache-2.0
9
+ short_description: Text-to-UI - Thanks to Pietro Schirano for the Repository!
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import pathlib
4
+ from PIL import Image
5
+ import google.generativeai as genai
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+ # Configure the API key directly in the script
10
+ API_KEY = os.environ.get("GOOGLE_API_KEY")
11
+ genai.configure(api_key=API_KEY)
12
+
13
+ # Generation configuration
14
+ generation_config = {
15
+ "temperature": 0.8,
16
+ "top_p": 0.95,
17
+ "top_k": 64,
18
+ "max_output_tokens": 50000,
19
+ "response_mime_type": "text/plain",
20
+ }
21
+
22
+ # Safety settings
23
+ safety_settings = [
24
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
25
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
26
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
27
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
28
+ ]
29
+
30
+ # Model name
31
+ MODEL_NAME = "gemini-1.5-flash-latest"
32
+
33
+ # Framework selection (e.g., Tailwind, Bootstrap, etc.)
34
+ framework = "Regular CSS use flex grid etc" # Change this to "Bootstrap" or any other framework as needed
35
+
36
+ # Create the model
37
+ model = genai.GenerativeModel(
38
+ model_name=MODEL_NAME,
39
+ safety_settings=safety_settings,
40
+ generation_config=generation_config,
41
+ )
42
+
43
+ # Start a chat session
44
+ chat_session = model.start_chat(history=[])
45
+
46
+ # Function to send a message to the model
47
+ def send_message_to_model(message, image_path):
48
+ image_input = {
49
+ 'mime_type': 'image/jpeg',
50
+ 'data': pathlib.Path(image_path).read_bytes()
51
+ }
52
+ response = chat_session.send_message([message, image_input])
53
+ return response.text
54
+
55
+ # Streamlit app
56
+ def main():
57
+ st.title("Image to HTML Code AI 👨‍💻 ")
58
+ st.subheader('Made by [Pushpendra](https://github.com/pushparmar).')
59
+
60
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
61
+
62
+ if uploaded_file is not None:
63
+ try:
64
+ # Load and display the image
65
+ image = Image.open(uploaded_file)
66
+ st.image(image, caption='Uploaded Image.', use_container_width=True)
67
+
68
+ # Convert image to RGB mode if it has an alpha channel
69
+ if image.mode == 'RGBA':
70
+ image = image.convert('RGB')
71
+
72
+ # Save the uploaded image temporarily
73
+ temp_image_path = pathlib.Path("temp_image.jpg")
74
+ image.save(temp_image_path, format="JPEG")
75
+ styleframework = st.selectbox("Select CSS Framework", ["Regular CSS use flex grid etc", "Bootstrap (Disabled)", "Tailwind (Disabled)"])
76
+ uiFrameWork = st.selectbox("Select UI Framework", ["Regular HTML Code", "React.js (Disabled)", "Angular.js (Disabled)", "Vue.js (Disabled)"])
77
+
78
+ # Generate UI description
79
+ if st.button("Code UI"):
80
+ placeholder = st.empty()
81
+ placeholder.write("🧑‍💻 A parmar code agent is Looking at your UI...")
82
+
83
+
84
+ import time
85
+ time.sleep(4)
86
+ st.write("🧑‍💻 A parmar code agent Generating Code for your image")
87
+ import time
88
+ time.sleep(2)
89
+ detailed_prompt = f"""
90
+ Analyze the uploaded image and generate a detailed {uiFrameWork} file with inline CSS that accurately represents the UI.
91
+ - Identify all UI elements (e.g., buttons, text fields, images, etc.) and their bounding boxes in the format: [object name (y_min, x_min, y_max, x_max)].
92
+ - Describe the color, font, and styling of each element.
93
+ - Ensure the {uiFrameWork} code is responsive and mobile-first, using {styleframework} CSS for layout and styling.
94
+ - If {uiFrameWork} is selected, generate components with selected framework syntax and include inline CSS for styling.
95
+ - Include detailed inline CSS for each element to match the original design as closely as possible.
96
+ - Avoid using external libraries or frameworks unless specified.
97
+ - Do not include explanations or comments in the code.
98
+ - ONLY return the {uiFrameWork} code with inline CSS.
99
+ """
100
+
101
+ if "Disabled" in uiFrameWork or "Disabled" in styleframework:
102
+ st.warning("This option is currently unavailable.")
103
+ return
104
+ else:
105
+ st.write(f"You selected: {uiFrameWork}")
106
+
107
+ generated_html = send_message_to_model(detailed_prompt, temp_image_path)
108
+ st.code(generated_html, language='html')
109
+
110
+ # Save the refined HTML to a file
111
+ with open("index.html", "w") as file:
112
+ file.write(generated_html)
113
+ st.success("HTML file 'index.html' has been created.")
114
+
115
+ # Provide download link for HTML
116
+ st.download_button(label="Download HTML", data=generated_html, file_name="index.html", mime="text/html")
117
+
118
+ # Provide a link to open the HTML file in a new tab
119
+ st.markdown(f'<a href="index.html" target="_blank">Open HTML in a new tab</a>', unsafe_allow_html=True)
120
+ except Exception as e:
121
+ st.error(f"An error occurred: {e}")
122
+
123
+ if __name__ == "__main__":
124
+ main()
index.html ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```html
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Growform</title>
8
+ <style>
9
+ body {
10
+ font-family: sans-serif;
11
+ margin: 0;
12
+ padding: 0;
13
+ background-color: #f8f9fa;
14
+ }
15
+ .container {
16
+ max-width: 600px;
17
+ margin: 50px auto;
18
+ background-color: #fff;
19
+ padding: 30px;
20
+ border-radius: 8px;
21
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
22
+ }
23
+ .logo {
24
+ display: flex;
25
+ align-items: center;
26
+ margin-bottom: 20px;
27
+ }
28
+ .logo img {
29
+ width: 32px;
30
+ height: 32px;
31
+ margin-right: 10px;
32
+ }
33
+ .logo span {
34
+ font-weight: bold;
35
+ font-size: 1.2rem;
36
+ color: #343a40;
37
+ }
38
+ .khoros-logo {
39
+ text-align: center;
40
+ margin-bottom: 20px;
41
+ }
42
+ .khoros-logo img {
43
+ height: 30px;
44
+ }
45
+ .khoros-logo span {
46
+ font-size: 24px;
47
+ color: #2862d6;
48
+ font-weight: bold;
49
+ }
50
+ .progress-bar {
51
+ display: flex;
52
+ justify-content: space-around;
53
+ margin-bottom: 20px;
54
+ }
55
+ .progress-bar circle {
56
+ width: 30px;
57
+ height: 30px;
58
+ border-radius: 50%;
59
+ border: 1px solid #ced4da;
60
+ display: flex;
61
+ justify-content: center;
62
+ align-items: center;
63
+ font-size: 14px;
64
+ color: #343a40;
65
+ background-color: #fff;
66
+ }
67
+ .progress-bar line {
68
+ height: 1px;
69
+ background-color: #ced4da;
70
+ }
71
+ .progress-bar circle.active {
72
+ background-color: #e94590;
73
+ color: #fff;
74
+ border: none;
75
+ }
76
+ label {
77
+ display: block;
78
+ margin-bottom: 5px;
79
+ font-size: 14px;
80
+ color: #343a40;
81
+ }
82
+ input[type="email"] {
83
+ width: 100%;
84
+ padding: 10px;
85
+ border: 1px solid #ced4da;
86
+ border-radius: 4px;
87
+ font-size: 16px;
88
+ margin-bottom: 20px;
89
+ }
90
+ .button {
91
+ width: 100%;
92
+ background-color: #e94590;
93
+ color: #fff;
94
+ padding: 12px 20px;
95
+ border: none;
96
+ border-radius: 4px;
97
+ font-size: 16px;
98
+ cursor: pointer;
99
+ }
100
+ .footer {
101
+ text-align: center;
102
+ margin-top: 30px;
103
+ font-size: 12px;
104
+ color: #868e96;
105
+ }
106
+ .footer a {
107
+ color: #868e96;
108
+ text-decoration: none;
109
+ margin: 0 5px;
110
+ }
111
+ </style>
112
+ </head>
113
+ <body>
114
+ <div class="container">
115
+ <div class="logo">
116
+ <img src="growform-logo.svg" alt="Growform Logo">
117
+ <span>Growform</span>
118
+ </div>
119
+ <div class="khoros-logo">
120
+ <img src="khoros-logo.svg" alt="Khoros Logo">
121
+ <span>Khoros</span>
122
+ </div>
123
+ <p style="text-align:center;margin-bottom:20px;font-size:16px;color:#343a40;">Are you ready for a demo?</p>
124
+ <div class="progress-bar">
125
+ <div class="circle active">1</div>
126
+ <div style="width: 25%;"></div>
127
+ <div class="circle">2</div>
128
+ <div style="width: 25%;"></div>
129
+ <div class="circle">3</div>
130
+ </div>
131
+ <p style="text-align: center; font-size: 16px; color: #343a40; margin-bottom: 20px;">Let's get started.</p>
132
+ <label for="work-email" style="margin-left: 5px;">Work email:</label>
133
+ <input type="email" id="work-email" style="margin-left:5px;">
134
+ <button class="button" style="margin-left:5px;">NEXT</button>
135
+ <div class="footer">
136
+ © Khoros, LLC | <a href="#">Privacy</a> | <a href="#">Security</a> | <a href="#">Disclaimer</a> | <a href="#">Legal & Compliance</a> | <a href="#">Terms of Use</a>
137
+ </div>
138
+ </div>
139
+ </body>
140
+ </html>
141
+ ```
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Pillow
2
+ google-generativeai
temp_image.jpg ADDED