adil9858 commited on
Commit
7dcb1ad
Β·
verified Β·
1 Parent(s): e807b08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -14,7 +14,7 @@ def encode_image(img):
14
  return encoded_string
15
 
16
  # Function to get explanation from VLM API
17
- def explain_image_with_vlm(image):
18
  api = "https://api.hyperbolic.xyz/v1/chat/completions"
19
  api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZGlsYXppejIwMTNAZ21haWwuY29tIiwiaWF0IjoxNzMyODU1NDI1fQ.lRjbz9LMW9jj7Lf7I8m_dTRh4KQ1wDCdWiTRGErMuEk"
20
 
@@ -30,7 +30,7 @@ def explain_image_with_vlm(image):
30
  {
31
  "role": "user",
32
  "content": [
33
- {"type": "text", "text": "Explain the Image in 10 words only"},
34
  {
35
  "type": "image_url",
36
  "image_url": {"url": f"data:image/jpeg;base64,{base64_img}"},
@@ -90,16 +90,22 @@ def styled_header(header_text):
90
  # Main Camera Input Section
91
  img_file_buffer = st.camera_input("πŸš€ Capture Your Image Here")
92
 
93
- if img_file_buffer:
 
 
 
 
 
 
94
  # Display captured image
95
  image = Image.open(img_file_buffer)
96
- #st.markdown(styled_header("πŸ“Έ Your Captured Image:"), unsafe_allow_html=True)
97
- #st.image(image, caption="Captured Image", use_column_width=True)
98
 
99
  st.markdown(styled_header("πŸ€– Image Analysis:"), unsafe_allow_html=True)
100
  with st.spinner("πŸ” The AI is analyzing your image. Please wait..."):
101
- explanation = explain_image_with_vlm(image)
102
- #st.success("✨ Analysis Complete!")
103
  st.write(f"**AI Insight:** {explanation}")
104
 
105
  # Footer
@@ -111,4 +117,4 @@ st.markdown(
111
  </footer>
112
  """,
113
  unsafe_allow_html=True
114
- )
 
14
  return encoded_string
15
 
16
  # Function to get explanation from VLM API
17
+ def explain_image_with_vlm(image, prompt):
18
  api = "https://api.hyperbolic.xyz/v1/chat/completions"
19
  api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZGlsYXppejIwMTNAZ21haWwuY29tIiwiaWF0IjoxNzMyODU1NDI1fQ.lRjbz9LMW9jj7Lf7I8m_dTRh4KQ1wDCdWiTRGErMuEk"
20
 
 
30
  {
31
  "role": "user",
32
  "content": [
33
+ {"type": "text", "text": prompt}, # Use the user-provided prompt
34
  {
35
  "type": "image_url",
36
  "image_url": {"url": f"data:image/jpeg;base64,{base64_img}"},
 
90
  # Main Camera Input Section
91
  img_file_buffer = st.camera_input("πŸš€ Capture Your Image Here")
92
 
93
+ # Text prompt input
94
+ user_prompt = st.text_input(
95
+ "πŸ“ Enter your prompt (e.g., 'Explain the image', 'What are the functions in this graph?', 'Describe the scene'):",
96
+ value="Explain the image in 10 words only"
97
+ )
98
+
99
+ if img_file_buffer and user_prompt:
100
  # Display captured image
101
  image = Image.open(img_file_buffer)
102
+ st.markdown(styled_header("πŸ“Έ Your Captured Image:"), unsafe_allow_html=True)
103
+ st.image(image, caption="Captured Image", use_column_width=True)
104
 
105
  st.markdown(styled_header("πŸ€– Image Analysis:"), unsafe_allow_html=True)
106
  with st.spinner("πŸ” The AI is analyzing your image. Please wait..."):
107
+ explanation = explain_image_with_vlm(image, user_prompt)
108
+ st.success("✨ Analysis Complete!")
109
  st.write(f"**AI Insight:** {explanation}")
110
 
111
  # Footer
 
117
  </footer>
118
  """,
119
  unsafe_allow_html=True
120
+ )