Dua Rajper commited on
Commit
314ee50
·
verified ·
1 Parent(s): 758dccc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -3,10 +3,7 @@ from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
3
  from PIL import Image
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,9 +34,9 @@ def groq_chat(prompt):
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}"
@@ -52,7 +49,7 @@ 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..."):
 
3
  from PIL import Image
4
  import easyocr
5
  import os
6
+ from groq import Groq, APIConnectionError, AuthenticationError
 
 
 
7
 
8
  # OCR Function
9
  def extract_text_from_image(image):
 
34
  model="llama-3.3-70b-versatile",
35
  )
36
  return chat_completion.choices[0].message.content
37
+ except APIConnectionError as e:
38
  return f"Groq API Connection Error: {e}"
39
+ except AuthenticationError as e:
40
  return f"Groq API Authentication Error: {e}"
41
  except Exception as e:
42
  return f"General Groq API Error: {e}"
 
49
 
50
  if uploaded_file is not None:
51
  image = Image.open(uploaded_file)
52
+ st.image(image, caption="Uploaded Image", use_container_width=True)
53
 
54
  if st.button("Extract Text and Enable Question Answering"):
55
  with st.spinner("Extracting text..."):