LuckyHappyFish commited on
Commit
56732d1
·
1 Parent(s): 4458d42

Initial Commit

Browse files
Files changed (2) hide show
  1. app.py +30 -12
  2. style.css +74 -0
app.py CHANGED
@@ -5,6 +5,21 @@ from huggingface_hub import InferenceClient
5
  import os
6
  from gradio_client import Client
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Hugging Face API key
9
  API_KEY = st.secrets["HF_API_KEY"]
10
 
@@ -49,20 +64,23 @@ def get_ingredients_qwen(food_name):
49
  st.title("Food Image Recognition with Ingredients")
50
 
51
  # Add banner image
52
- st.image("IR_IMAGE.png", caption="Food Recognition Model", use_container_width=True)
53
 
54
  # Sidebar for model information
55
- st.sidebar.title("Model Information")
56
- st.sidebar.write("**Image Classification Model**: Shresthadev403/food-image-classification")
57
- st.sidebar.write("**LLM for Ingredients**: Qwen/Qwen2.5-Coder-32B-Instruct")
 
 
 
58
 
59
- # Upload image
60
  uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
61
 
62
  if uploaded_file is not None:
63
  # Display the uploaded image
64
  image = Image.open(uploaded_file)
65
- st.image(image, caption="Uploaded Image", use_container_width=True)
66
  st.write("Classifying...")
67
 
68
  # Make predictions
@@ -80,13 +98,13 @@ if uploaded_file is not None:
80
  except Exception as e:
81
  st.error(f"Error generating ingredients: {e}")
82
 
83
- st.subheader("Healthier alternatives:")
84
  try:
85
- client = Client("https://8a56cb969da1f9d721.gradio.live/")
86
- result = client.predict(query=f"What's a healthy {top_food} recipe, and why is it healthy?", api_name="/get_response")
 
 
 
87
  st.write(result)
88
  except Exception as e:
89
  st.error(f"Unable to contact RAG: {e}")
90
-
91
- # Footer
92
- st.sidebar.markdown("Developed by Muhammad Hassan Butt.")
 
5
  import os
6
  from gradio_client import Client
7
 
8
+ # Set page configuration
9
+ st.set_page_config(
10
+ page_title="Food Image Recognition with Ingredients",
11
+ page_icon="🍔",
12
+ layout="wide",
13
+ initial_sidebar_state="expanded",
14
+ )
15
+
16
+ # Custom CSS to improve styling and responsiveness
17
+ def local_css(file_name):
18
+ with open(file_name) as f:
19
+ st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
20
+
21
+ local_css("style.css")
22
+
23
  # Hugging Face API key
24
  API_KEY = st.secrets["HF_API_KEY"]
25
 
 
64
  st.title("Food Image Recognition with Ingredients")
65
 
66
  # Add banner image
67
+ st.image("IR_IMAGE.png", caption="Food Recognition Model", use_column_width=True)
68
 
69
  # Sidebar for model information
70
+ with st.sidebar:
71
+ st.title("Model Information")
72
+ st.write("**Image Classification Model**: Shresthadev403/food-image-classification")
73
+ st.write("**LLM for Ingredients**: Qwen/Qwen2.5-Coder-32B-Instruct")
74
+ st.markdown("---")
75
+ st.markdown("<p style='text-align: center;'>Developed by Muhammad Hassan Butt.</p>", unsafe_allow_html=True)
76
 
77
+ # Main content
78
  uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
79
 
80
  if uploaded_file is not None:
81
  # Display the uploaded image
82
  image = Image.open(uploaded_file)
83
+ st.image(image, caption="Uploaded Image", use_column_width=True)
84
  st.write("Classifying...")
85
 
86
  # Make predictions
 
98
  except Exception as e:
99
  st.error(f"Error generating ingredients: {e}")
100
 
101
+ st.subheader("Healthier Alternatives")
102
  try:
103
+ client_gradio = Client("https://8a56cb969da1f9d721.gradio.live/")
104
+ result = client_gradio.predict(
105
+ query=f"What's a healthy {top_food} recipe, and why is it healthy?",
106
+ api_name="/get_response"
107
+ )
108
  st.write(result)
109
  except Exception as e:
110
  st.error(f"Unable to contact RAG: {e}")
 
 
 
style.css ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* General settings */
2
+ body {
3
+ background-color: #f5f5f5;
4
+ }
5
+
6
+ /* Title styling */
7
+ h1 {
8
+ text-align: center;
9
+ color: #333333;
10
+ font-size: 2.5rem;
11
+ margin-bottom: 20px;
12
+ }
13
+
14
+ /* Image styling */
15
+ .st-image > img {
16
+ border-radius: 10px;
17
+ margin-bottom: 20px;
18
+ }
19
+
20
+ /* Sidebar styling */
21
+ .css-1d391kg {
22
+ background-color: #ffffff;
23
+ border-right: 1px solid #e6e6e6;
24
+ }
25
+
26
+ .stSidebar > div {
27
+ padding: 20px;
28
+ }
29
+
30
+ /* Text elements */
31
+ h2 {
32
+ color: #4285F4;
33
+ margin-top: 30px;
34
+ }
35
+
36
+ h3 {
37
+ color: #333333;
38
+ }
39
+
40
+ /* File uploader styling */
41
+ .css-1cpxqw2 {
42
+ background-color: #4285F4;
43
+ color: #ffffff;
44
+ border: none;
45
+ border-radius: 5px;
46
+ }
47
+
48
+ .css-1cpxqw2:hover {
49
+ background-color: #357ae8;
50
+ color: #ffffff;
51
+ }
52
+
53
+ /* Footer styling */
54
+ footer {
55
+ visibility: hidden;
56
+ }
57
+
58
+ /* Adjustments for mobile devices */
59
+ @media only screen and (max-width: 600px) {
60
+ /* Adjust title size */
61
+ h1 {
62
+ font-size: 2rem;
63
+ }
64
+
65
+ /* Adjust image size */
66
+ .st-image > img {
67
+ width: 100%;
68
+ }
69
+
70
+ /* Sidebar adjustments */
71
+ .css-1d391kg {
72
+ width: 100%;
73
+ }
74
+ }