Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
+
|
6 |
+
genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
|
7 |
+
|
8 |
+
model=genai.GenerativeModel('gemini-1.5-pro-latest')
|
9 |
+
input_prompt = """
|
10 |
+
As an HTML and CSS expert, your task is to create complete HTML and CSS code based on the provided screenshot, ensuring clear and functional markup. Provide a main.html file with inline CSS that replicates the exact color and style as shown in the given screenshot.
|
11 |
+
Output structure:
|
12 |
+
Start and end with (```)
|
13 |
+
"""
|
14 |
+
|
15 |
+
def generate_response(input_prompt,image):
|
16 |
+
response = model.generate_content([input_prompt,image[0]])
|
17 |
+
# print(response.text)
|
18 |
+
return response.text
|
19 |
+
|
20 |
+
def input_image_setup(uploaded_file):
|
21 |
+
# Check if a file has been uploaded
|
22 |
+
if uploaded_file is not None:
|
23 |
+
# Read the file into bytes
|
24 |
+
bytes_data = uploaded_file.getvalue()
|
25 |
+
|
26 |
+
image_parts = [
|
27 |
+
{
|
28 |
+
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
29 |
+
"data": bytes_data
|
30 |
+
}
|
31 |
+
]
|
32 |
+
return image_parts
|
33 |
+
else:
|
34 |
+
raise FileNotFoundError("No file uploaded")
|
35 |
+
|
36 |
+
st.title("SCREENSHORT - HTML CODE📃")
|
37 |
+
st.text("Uploade your demo webpage image Here:")
|
38 |
+
|
39 |
+
upload_file = st.file_uploader('',type=['jpg','jpeg','png'])
|
40 |
+
if upload_file is not None:
|
41 |
+
image = Image.open(upload_file)
|
42 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
43 |
+
|
44 |
+
submit = st.button('Create a webpage')
|
45 |
+
if submit:
|
46 |
+
image_data = input_image_setup(uploaded_file=upload_file)
|
47 |
+
with st.spinner("Building the Webpage..."):
|
48 |
+
response = generate_response(input_prompt, image_data)
|
49 |
+
st.subheader("CODE:")
|
50 |
+
st.markdown(response)
|