CoolFace
Apppublic

IYAPPA007/Screenshot-HTML

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1import streamlit as st2import google.generativeai as genai3from PIL import Image4import os5 6genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))7 8model=genai.GenerativeModel('gemini-1.5-pro-latest')9input_prompt = """10As 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.11Output structure:12Start and end with (```)13"""14 15def generate_response(input_prompt,image):16    response = model.generate_content([input_prompt,image[0]])17    # print(response.text)18    return response.text19 20def input_image_setup(uploaded_file):21    # Check if a file has been uploaded22    if uploaded_file is not None:23        # Read the file into bytes24        bytes_data = uploaded_file.getvalue()25 26        image_parts = [27            {28                "mime_type": uploaded_file.type,  # Get the mime type of the uploaded file29                "data": bytes_data30            }31        ]32        return image_parts33    else:34        raise FileNotFoundError("No file uploaded")35    36st.title("SCREENSHOT - HTML CODE📃")37st.text("Uploade your demo webpage image Here:")38 39upload_file = st.file_uploader('',type=['jpg','jpeg','png'])40if upload_file is not None:41    image = Image.open(upload_file)42    st.image(image, caption="Uploaded Image", use_column_width=True)43    44submit = st.button('Create a webpage')45if 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)