File size: 1,739 Bytes
bf20db9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac8e824
bf20db9
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import google.generativeai as genai
from PIL import Image
import os

genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))

model=genai.GenerativeModel('gemini-1.5-pro-latest')
input_prompt = """
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.
Output structure:
Start and end with (```)
"""

def generate_response(input_prompt,image):
    response = model.generate_content([input_prompt,image[0]])
    # print(response.text)
    return response.text

def input_image_setup(uploaded_file):
    # Check if a file has been uploaded
    if uploaded_file is not None:
        # Read the file into bytes
        bytes_data = uploaded_file.getvalue()

        image_parts = [
            {
                "mime_type": uploaded_file.type,  # Get the mime type of the uploaded file
                "data": bytes_data
            }
        ]
        return image_parts
    else:
        raise FileNotFoundError("No file uploaded")
    
st.title("SCREENSHOT - HTML CODE📃")
st.text("Uploade your demo webpage image Here:")

upload_file = st.file_uploader('',type=['jpg','jpeg','png'])
if upload_file is not None:
    image = Image.open(upload_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)
    
submit = st.button('Create a webpage')
if submit:
    image_data = input_image_setup(uploaded_file=upload_file)
    with st.spinner("Building the Webpage..."):
        response = generate_response(input_prompt, image_data)
        st.subheader("CODE:")
        st.markdown(response)