NBayer commited on
Commit
0d406fd
1 Parent(s): 5c37675

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -4
app.py CHANGED
@@ -2,8 +2,7 @@ import streamlit as st
2
  from streamlit.components.v1 import html
3
  import os
4
  import PyPDF2
5
-
6
- st.write(os.environ("TEST"))
7
 
8
  def get_pdf_text(pdf_path):
9
  # creating a pdf file object
@@ -24,6 +23,22 @@ def get_pdf_text(pdf_path):
24
 
25
  return pdf_text
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  tab_general_topics, tab_your_paper = st.tabs(["Research topics", "Summarize your paper(s)"])
28
 
29
  with tab_general_topics:
@@ -46,7 +61,7 @@ with tab_your_paper:
46
  for pdf in pdf_files:
47
  # Saving the files
48
  pdf_data = pdf.getvalue()
49
- pdf_path = os.path.join(pdf.name)
50
  with open(pdf_path, "wb") as f:
51
  f.write(pdf_data)
52
  recently_added.append(pdf_path)
@@ -55,6 +70,7 @@ with tab_your_paper:
55
  for recent_pdf in recently_added:
56
  # Reading the pdf files
57
  pdf_content = get_pdf_text(recent_pdf)
 
58
  pdfs_content_list.append(pdf_content)
59
 
60
  # Delete the files
@@ -62,4 +78,33 @@ with tab_your_paper:
62
 
63
  all_text_together = " ".join(pdfs_content_list)
64
 
65
- st.write(all_text_together)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from streamlit.components.v1 import html
3
  import os
4
  import PyPDF2
5
+ import requests
 
6
 
7
  def get_pdf_text(pdf_path):
8
  # creating a pdf file object
 
23
 
24
  return pdf_text
25
 
26
+ headers = {"Authorization": "Bearer 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"}
27
+
28
+ def create_tags(payload):
29
+ API_URL_TAGS = "https://api-inference.huggingface.co/models/fabiochiu/t5-base-tag-generation"
30
+
31
+ response = requests.post(API_URL_TAGS, headers=headers, json=payload)
32
+ return response.json()
33
+
34
+ def summarize_text(payload):
35
+ API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
36
+ response = requests.post(API_URL, headers=headers, json=payload)
37
+ return response.json()
38
+
39
+
40
+ # Start of the app code
41
+
42
  tab_general_topics, tab_your_paper = st.tabs(["Research topics", "Summarize your paper(s)"])
43
 
44
  with tab_general_topics:
 
61
  for pdf in pdf_files:
62
  # Saving the files
63
  pdf_data = pdf.getvalue()
64
+ pdf_path = os.path.join("pdfs", pdf.name)
65
  with open(pdf_path, "wb") as f:
66
  f.write(pdf_data)
67
  recently_added.append(pdf_path)
 
70
  for recent_pdf in recently_added:
71
  # Reading the pdf files
72
  pdf_content = get_pdf_text(recent_pdf)
73
+ print("**", pdf_content)
74
  pdfs_content_list.append(pdf_content)
75
 
76
  # Delete the files
 
78
 
79
  all_text_together = " ".join(pdfs_content_list)
80
 
81
+ try:
82
+ tags = create_tags({
83
+ "inputs": all_text_together,
84
+ })[0]["generated_text"]
85
+ tags_available = True
86
+ except:
87
+ tags_available = False
88
+
89
+ summary = summarize_text({
90
+ "inputs": all_text_together
91
+ })[0]["summary_text"]
92
+
93
+ col1, col2 = st.columns(2)
94
+ with col1:
95
+ if len(recently_added) > 1:
96
+ st.markdown("#### Summary of your paper(s):")
97
+ else:
98
+ st.markdown("#### Summary of your paper:")
99
+ st.write(summary)
100
+
101
+ if tags_available == True:
102
+ with col2:
103
+ if len(recently_added) > 1:
104
+ st.markdown("#### Identified topics of your paper(s):")
105
+ else:
106
+ st.markdown("#### Identified topics of your paper:")
107
+ st.write(tags)
108
+
109
+ with st.expander("See your total text"):
110
+ st.write(all_text_together)