File size: 1,965 Bytes
dfe3e5a
7d4a989
a3f4b09
 
 
7d4a989
 
dfe3e5a
7d4a989
a3f4b09
 
dfe3e5a
 
7d4a989
 
a3f4b09
 
dfe3e5a
7d4a989
dfe3e5a
a3f4b09
dfe3e5a
a3f4b09
 
dfe3e5a
7d4a989
a3f4b09
7d4a989
a3f4b09
 
 
 
 
7d4a989
 
dfe3e5a
 
 
 
 
 
 
 
 
 
 
 
b650ca3
 
2fe758d
ceea7bc
b650ca3
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
# Import libraries
from dotenv import load_dotenv
import os
import google.generativeai as genai
from PIL import Image
import streamlit as st

# Load API Key
load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

# Function to load Google Gemini Vision model and get response
def get_response_code(image, prompt):
    model = genai.GenerativeModel('gemini-pro-vision')
    response = model.generate_content([image[0], prompt])
    return response.text

# Function to preprocess image data
def prep_image(uploaded_file):
    # Check if there is any data
    if uploaded_file is not None:
        # Read the file as bytes
        bytes_data = uploaded_file.getvalue()

        # Get the image part information
        image_parts = [
            {
                "mime_type": uploaded_file.type,
                "data": bytes_data
            }
        ]
        return image_parts
    else:
        raise FileNotFoundError("No File is uploaded!")

# Configuring Streamlit App
st.set_page_config(page_title="Code Interpreter")
st.image('LOGO.jpg', width=70)
st.header("Code Interpreter")

# Section for Code Interpreter
upload_code_file = st.file_uploader("Choose an image of code...", type=["jpg", "jpeg", "png"])
if upload_code_file is not None:
    # Show the uploaded code image
    code_image = Image.open(upload_code_file)
    st.image(code_image, caption="Uploaded Code Image", use_column_width=True)

    # Prompt Template for code interpretation
    input_prompt_code = """
    CONVERT THE IMAGES TO TEXT , IF THERE ARE OPTIONS DO NOT FORGET TO INCLUDE OPTIONS IF THERE ARE THERE
    
    """

    # Button for code interpretation
    submit = st.button("Interpret Code!")
    if submit:
        code_image_data = prep_image(upload_code_file)
        response = get_response_code(code_image_data, input_prompt_code)
        st.subheader("Code AI: ")
        st.write(response)
else:
    st.info("Please upload an image of the code to proceed.")