Dua Rajper commited on
Commit
a2b4d1f
·
verified ·
1 Parent(s): f8d60e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -4,6 +4,9 @@ from PIL import Image
4
  import easyocr
5
  import os
6
  from groq import Groq
 
 
 
7
 
8
  # OCR Function
9
  def extract_text_from_image(image):
@@ -34,8 +37,12 @@ def groq_chat(prompt):
34
  model="llama-3.3-70b-versatile",
35
  )
36
  return chat_completion.choices[0].message.content
 
 
 
 
37
  except Exception as e:
38
- return f"Error using Groq API: {e}. Please ensure GROQ_API_KEY is set correctly."
39
 
40
  # Streamlit App
41
  def main():
@@ -45,7 +52,7 @@ def main():
45
 
46
  if uploaded_file is not None:
47
  image = Image.open(uploaded_file)
48
- st.image(image, caption="Uploaded Image", use_column_width=True)
49
 
50
  if st.button("Extract Text and Enable Question Answering"):
51
  with st.spinner("Extracting text..."):
 
4
  import easyocr
5
  import os
6
  from groq import Groq
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv() # Load environment variables from .env
10
 
11
  # OCR Function
12
  def extract_text_from_image(image):
 
37
  model="llama-3.3-70b-versatile",
38
  )
39
  return chat_completion.choices[0].message.content
40
+ except groq.APIConnectionError as e:
41
+ return f"Groq API Connection Error: {e}"
42
+ except groq.AuthenticationError as e:
43
+ return f"Groq API Authentication Error: {e}"
44
  except Exception as e:
45
+ return f"General Groq API Error: {e}"
46
 
47
  # Streamlit App
48
  def main():
 
52
 
53
  if uploaded_file is not None:
54
  image = Image.open(uploaded_file)
55
+ st.image(image, caption="Uploaded Image", use_container_width=True) # Changed here
56
 
57
  if st.button("Extract Text and Enable Question Answering"):
58
  with st.spinner("Extracting text..."):