Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified README.md
Binary file not shown.
83 changes: 77 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,71 @@
#make a stremlit aplication to import a pdf file and convert it to text and display text in another output window and an option to download file generated
import streamlit as st
import os

import multiprocessing
from functools import wraps
from langchain.llms import OpenAI
from langchain.document_loaders import TextLoader
from langchain.document_loaders import PyPDFLoader
from langchain.prompts import PromptTemplate

import urllib.request
def connect(host='http://google.com'):
try:
urllib.request.urlopen(host) #Python 3.x
return True
except:
return False



def parametrized(dec):
def layer(*args, **kwargs):
def repl(f):
return dec(f, *args, **kwargs)
return repl
return layer
def function_runner(*args, **kwargs):
"""Used as a wrapper function to handle
returning results on the multiprocessing side"""

send_end = kwargs.pop("__send_end")
function = kwargs.pop("__function")
try:
result = function(*args, **kwargs)
except Exception as e:
send_end.send(e)
return
send_end.send(result)

@parametrized
def run_with_timer(func, max_execution_time):
@wraps(func)
def wrapper(*args, **kwargs):
recv_end, send_end = multiprocessing.Pipe(False)
kwargs["__send_end"] = send_end
kwargs["__function"] = func

## PART 2
p = multiprocessing.Process(target=function_runner, args=args, kwargs=kwargs)
p.start()
p.join(max_execution_time)
if p.is_alive():
p.terminate()
p.join()
#raise TimeExceededException("OpenAI taking too long to respond")
st.error("OpenAI taking too long to respond. Refresh and Restart again.")
result = recv_end.recv()

if isinstance(result, Exception):
#raise result
st.error(result)


return result

return wrapper

@run_with_timer(max_execution_time=20)
def op_readme():
llm = OpenAI()

Expand All @@ -26,12 +85,13 @@ def op_readme():
)

from langchain.chains import LLMChain

chain = LLMChain(llm=llm, prompt=prompt)

# Run the chain only specifying the input variable.
j=0

os.remove("result.md")
file="result.md"
if os.path.exists(file):
os.remove("result.md")

with open('result.md', 'w') as f:
for i in range(0,len(full_content),2000):
Expand All @@ -43,18 +103,26 @@ def op_readme():

return "Success"



#signal.signal(signal.SIGALRM, timeout_handler)
st.title("Slides Summarizer \n(PDF to Markdown)")
os.environ["OPENAI_API_KEY"] = st.text_input("Enter your OpenAI API Key")


file = st.file_uploader("Upload Your Slides", type="pdf")
if file:
if os.environ["OPENAI_API_KEY"] == "":
st.write("Please enter your API key")
#print(openai.api_key )
st.error("Please enter your API key")
else:
with open("slides.pdf", "wb") as f:
f.write(file.getbuffer())
st.success("Saved File Successfully")
if(not connect()):
st.error("No Internet!")
while(not connect()):
pass
st.success("Connected to Internet Successfully")
pdf = op_readme()
if pdf=="Success":
st.write("File converted successfully. Download the file to view the summary.")
Expand All @@ -66,3 +134,6 @@ def op_readme():
mime='text/markdown'
)




3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pandas
requests
paytmchecksum
langchain
openai
requests
urllib