mkoot007 commited on
Commit
704ef61
·
1 Parent(s): 0a77cb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,23 +1,20 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
 
3
 
4
- # Create a text2text-generation pipeline
5
- pipe = pipeline("text2text-generation", model="kaist-ai/prometheus-13b-v1.0")
6
 
7
  st.title("Text Classification Model")
8
  uploaded_file = st.file_uploader("Upload an image:")
9
 
10
  if uploaded_file is not None:
11
- # Read the uploaded image
12
  image = Image.open(uploaded_file)
13
-
14
- # Extract text from the image using OCR
15
- ocr_results = extract_text(image)
16
  extracted_text = " ".join([res[1] for res in ocr_results])
17
  st.markdown("**Extracted text:**")
18
  st.markdown(extracted_text)
19
-
20
- # Generate an explanation for the extracted text using the Hugging Face pipeline
21
  explanation = pipe(extracted_text, max_length=100, do_sample=True)[0]["generated_text"]
22
  st.markdown("**Explanation:**")
23
  st.markdown(explanation)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from PIL import Image
4
+ import easyocr
5
 
6
+ pipe = pipeline("text2text-generation", model="google/flan-t5-base")
 
7
 
8
  st.title("Text Classification Model")
9
  uploaded_file = st.file_uploader("Upload an image:")
10
 
11
  if uploaded_file is not None:
 
12
  image = Image.open(uploaded_file)
13
+ ocr_reader = easyocr.Reader(['en'])
14
+ ocr_results = ocr_reader.readtext(image)
 
15
  extracted_text = " ".join([res[1] for res in ocr_results])
16
  st.markdown("**Extracted text:**")
17
  st.markdown(extracted_text)
 
 
18
  explanation = pipe(extracted_text, max_length=100, do_sample=True)[0]["generated_text"]
19
  st.markdown("**Explanation:**")
20
  st.markdown(explanation)