Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +8 -0
- summarize.py +25 -0
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain-community
|
| 2 |
+
llms
|
| 3 |
+
PIL
|
| 4 |
+
numpy
|
| 5 |
+
dotenv
|
| 6 |
+
streamlit
|
| 7 |
+
easyocr
|
| 8 |
+
os
|
summarize.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.llms import OpenAI
|
| 2 |
+
import os
|
| 3 |
+
import PIL
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image, ImageDraw
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
load_dotenv()
|
| 8 |
+
import streamlit as st
|
| 9 |
+
import easyocr
|
| 10 |
+
from langchain.prompts import PromptTemplate
|
| 11 |
+
st.header("Summarizer")
|
| 12 |
+
reader = easyocr.Reader(['en'])
|
| 13 |
+
uploaded_file=st.file_uploader("Upload image:")
|
| 14 |
+
llm=OpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"),temperature=0.7)
|
| 15 |
+
pt=PromptTemplate(input_variables=["text"],template="Read the following text: {text} and give the important points in the form of bullet points. ")
|
| 16 |
+
from langchain.chains import LLMChain
|
| 17 |
+
chain=LLMChain(llm=llm,prompt=pt)
|
| 18 |
+
if uploaded_file is not None:
|
| 19 |
+
image = Image.open(uploaded_file)
|
| 20 |
+
st.image(image)
|
| 21 |
+
result = reader.readtext(np.array(image), detail = 0)
|
| 22 |
+
st.subheader("OCR result:")
|
| 23 |
+
st.write(result)
|
| 24 |
+
st.subheader("Summary: ")
|
| 25 |
+
st.write(chain.invoke(result)["text"])
|