Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-pro-vision')
|
| 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 same color and style as the given screenshot.
|
| 11 |
+
|
| 12 |
+
Output structure:
|
| 13 |
+
Start and end with (```)
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
def generate_response(input_prompt,image):
|
| 17 |
+
response = model.generate_content([input_prompt,image[0]])
|
| 18 |
+
# print(response.text)
|
| 19 |
+
return response.text
|
| 20 |
+
|
| 21 |
+
def input_image_setup(uploaded_file):
|
| 22 |
+
# Check if a file has been uploaded
|
| 23 |
+
if uploaded_file is not None:
|
| 24 |
+
# Read the file into bytes
|
| 25 |
+
bytes_data = uploaded_file.getvalue()
|
| 26 |
+
|
| 27 |
+
image_parts = [
|
| 28 |
+
{
|
| 29 |
+
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
| 30 |
+
"data": bytes_data
|
| 31 |
+
}
|
| 32 |
+
]
|
| 33 |
+
return image_parts
|
| 34 |
+
else:
|
| 35 |
+
raise FileNotFoundError("No file uploaded")
|
| 36 |
+
|
| 37 |
+
st.title("SCREENSHORT - HTML CODE📃")
|
| 38 |
+
st.text("Uploade your demo website image Here:")
|
| 39 |
+
|
| 40 |
+
upload_file = st.file_uploader('',type=['jpg','jpeg','png'])
|
| 41 |
+
if upload_file is not None:
|
| 42 |
+
image = Image.open(upload_file)
|
| 43 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 44 |
+
|
| 45 |
+
submit = st.button('Create a webpage')
|
| 46 |
+
if submit:
|
| 47 |
+
image_data = input_image_setup(uploaded_file=upload_file)
|
| 48 |
+
with st.spinner("Processing..."):
|
| 49 |
+
response = generate_response(input_prompt, image_data)
|
| 50 |
+
st.subheader("CODE:")
|
| 51 |
+
st.markdown(response)
|