-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwith_payment.py
More file actions
80 lines (62 loc) · 2.67 KB
/
with_payment.py
File metadata and controls
80 lines (62 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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
from razorpay_button import razorpay_button
from langchain.llms import OpenAI
from langchain.document_loaders import TextLoader
from langchain.document_loaders import PyPDFLoader
from langchain.prompts import PromptTemplate
def op_readme():
llm = OpenAI()
loader = PyPDFLoader("slides.pdf")
documents = loader.load()
full_content = ""
for i in documents:
full_content+=(" "+i.page_content)
print(len(full_content))
llm = OpenAI(temperature=0.1)
prompt = PromptTemplate(
input_variables=["doc"],
template="You are an expert in Summarising slides. Here is the text of an OCRed PDF containing course material. Your job is to give a very short structured summary (less that half of number of characters in the information) of below information with clear headings and brief text to aid with my exam prep. Give output in Markdown.\nINFORMATION:{doc}",
)
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")
with open('result.md', 'w') as f:
for i in range(0,len(full_content),2000):
print(i,"\n")
out = str(chain.run(full_content[j:i]))
f.write(out+"\n")
print(out)
j=i
return "Success"
st.title("Slides Summarizer \n(PDF to Markdown)")
import streamlit as st
def show_razorpay_button():
st.markdown("""
<iframe src="D:/PaperPal/Slides2Notes/razorpay_button/razorpay_button.html" frameborder="0" scrolling="no" width="450" height="400"></iframe>
""", unsafe_allow_html=True)
# Add the Razorpay button
show_razorpay_button()
# Rest of your app code
os.environ["OPENAI_API_KEY"] = "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"
file = st.file_uploader("Upload Your Slides", type="pdf")
if file:
if os.environ["OPENAI_API_KEY"] == "":
st.write("Please enter your API key")
else:
with open("slides.pdf", "wb") as f:
f.write(file.getbuffer())
st.success("Saved File Successfully")
pdf = op_readme()
if pdf=="Success":
st.write("File converted successfully. Download the file to view the summary.")
with open("result.md", "rb") as fi:
st.download_button(
label="Download Markdown file of Summary",
data=fi,
file_name='result.md',
mime='text/markdown'
)