Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,28 @@
|
|
1 |
-
#Import libraries
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
from PIL import Image
|
6 |
import streamlit as st
|
7 |
|
8 |
-
|
9 |
-
#Load API Key
|
10 |
load_dotenv()
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
13 |
-
#Function to load Google Gemini
|
14 |
-
def
|
15 |
-
model = genai.GenerativeModel('gemini-pro')
|
16 |
-
response = model.generate_content([prompt, input])
|
17 |
-
return response.text
|
18 |
-
|
19 |
-
#Function to load Google Gemini Vision model and get response
|
20 |
-
def get_response_nutrition(image, prompt):
|
21 |
model = genai.GenerativeModel('gemini-pro-vision')
|
22 |
response = model.generate_content([image[0], prompt])
|
23 |
return response.text
|
24 |
|
25 |
-
#
|
26 |
def prep_image(uploaded_file):
|
27 |
-
#Check if there is any data
|
28 |
if uploaded_file is not None:
|
29 |
-
#Read the file as bytes
|
30 |
bytes_data = uploaded_file.getvalue()
|
31 |
|
32 |
-
#
|
33 |
image_parts = [
|
34 |
{
|
35 |
"mime_type": uploaded_file.type,
|
@@ -39,65 +32,29 @@ def prep_image(uploaded_file):
|
|
39 |
return image_parts
|
40 |
else:
|
41 |
raise FileNotFoundError("No File is uploaded!")
|
42 |
-
|
43 |
-
#Configuring Streamlit App
|
44 |
-
#st.set_page_config(page_title="Health Management: Nutrition Calculator & Diet Planner")
|
45 |
-
st.image('LOGO.jpg', width=70)
|
46 |
-
st.header("Health: Nutrition Calculator & Diet Planner")
|
47 |
-
|
48 |
-
######################################################################################
|
49 |
-
section_choice1 = st.radio("Choose Section:", ("Nutrition Calculator","Diet Planner"))
|
50 |
-
|
51 |
-
#If choice is nutrition calculator
|
52 |
-
if section_choice1 == "Nutrition Calculator":
|
53 |
-
upload_file = st.file_uploader("Choose an image...", type=["jpg","jpeg","png"])
|
54 |
-
image = ""
|
55 |
-
if upload_file is not None:
|
56 |
-
#Show the image
|
57 |
-
image = Image.open(upload_file)
|
58 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
You are an expert Nutritionist.
|
87 |
-
If the input contains list of items like fruits or vegetables, you have to give diet plan and suggest
|
88 |
-
breakfast, lunch, dinner wrt given item.
|
89 |
-
If the input contains numbers, you have to suggest diet plan for breakfast, luncg=h, dinner within
|
90 |
-
given number of calorie for the whole day.
|
91 |
-
Score yourself in terms of Accuracy and Precision on calories you predict
|
92 |
-
|
93 |
-
Return the response using markdown. Also score yourself in terms of accuracy and Precision
|
94 |
-
|
95 |
-
"""
|
96 |
-
##if the button is clicked
|
97 |
-
input_diet = st.text_area(" Input the list of items that you have at home and get diet plan! OR \
|
98 |
-
Input how much calorie you want to intake perday?:")
|
99 |
-
submit1 = st.button("Plan my Diet!")
|
100 |
-
if submit1:
|
101 |
-
response = get_response_diet(input_prompt_diet, input_diet)
|
102 |
-
st.subheader("Diet AI: ")
|
103 |
-
st.write(response)
|
|
|
1 |
+
# Import libraries
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
4 |
import google.generativeai as genai
|
5 |
from PIL import Image
|
6 |
import streamlit as st
|
7 |
|
8 |
+
# Load API Key
|
|
|
9 |
load_dotenv()
|
10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
11 |
|
12 |
+
# Function to load Google Gemini Vision model and get response
|
13 |
+
def get_response_code(image, prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
model = genai.GenerativeModel('gemini-pro-vision')
|
15 |
response = model.generate_content([image[0], prompt])
|
16 |
return response.text
|
17 |
|
18 |
+
# Function to preprocess image data
|
19 |
def prep_image(uploaded_file):
|
20 |
+
# Check if there is any data
|
21 |
if uploaded_file is not None:
|
22 |
+
# Read the file as bytes
|
23 |
bytes_data = uploaded_file.getvalue()
|
24 |
|
25 |
+
# Get the image part information
|
26 |
image_parts = [
|
27 |
{
|
28 |
"mime_type": uploaded_file.type,
|
|
|
32 |
return image_parts
|
33 |
else:
|
34 |
raise FileNotFoundError("No File is uploaded!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# Configuring Streamlit App
|
37 |
+
st.set_page_config(page_title="Code Interpreter")
|
38 |
+
st.image('LOGO.jpg', width=70)
|
39 |
+
st.header("Code Interpreter")
|
40 |
+
|
41 |
+
# Section for Code Interpreter
|
42 |
+
upload_code_file = st.file_uploader("Choose an image of code...", type=["jpg", "jpeg", "png"])
|
43 |
+
if upload_code_file is not None:
|
44 |
+
# Show the uploaded code image
|
45 |
+
code_image = Image.open(upload_code_file)
|
46 |
+
st.image(code_image, caption="Uploaded Code Image", use_column_width=True)
|
47 |
+
|
48 |
+
# Prompt Template for code interpretation
|
49 |
+
input_prompt_code = """
|
50 |
+
You are an expert in coding. The image contains a piece of code. Your task is to interpret the code and solve the problem it presents.
|
51 |
+
Provide an analysis of the code, its functionality, and any potential improvements or solutions.
|
52 |
+
"""
|
53 |
+
|
54 |
+
# Button for code interpretation
|
55 |
+
submit = st.button("Interpret Code!")
|
56 |
+
if submit:
|
57 |
+
code_image_data = prep_image(upload_code_file)
|
58 |
+
response = get_response_code(code_image_data, input_prompt_code)
|
59 |
+
st.subheader("Code AI: ")
|
60 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|