-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pika, sys, os, PyPDF2 | ||
from transformers import pipeline | ||
|
||
summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf") | ||
|
||
def main(): | ||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) | ||
channel = connection.channel() | ||
|
||
channel.queue_declare(queue='sendPDF') | ||
|
||
def callback(ch, method, properties, body): | ||
print(f" [x] Received {body}") | ||
|
||
pdfGet = body.decode() | ||
# Open the PDF file in read-binary mode | ||
with open(pdfGet, 'rb') as file: | ||
# Create a PDF object | ||
pdf = PyPDF2.PdfReader(file) | ||
# Get the number of pages in the PDF | ||
page = pdf.pages[6] | ||
text = page.extract_text() | ||
summary = summarizer(text, max_length=100, min_length=30, do_sample=False) | ||
sum = (summary[0]['summary_text']) | ||
channel.queue_declare(queue='sendTxt') | ||
channel.basic_publish(exchange='', routing_key='sendTxt', body=sum) | ||
print(" [x] Sent 'A message getText'") | ||
|
||
|
||
channel.basic_consume(queue='sendPDF', on_message_callback=callback, auto_ack=True) | ||
|
||
print(' [*] Waiting for messages. To exit press CTRL+C') | ||
|
||
channel.start_consuming() | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
print('Interrupted') | ||
try: | ||
sys.exit(0) | ||
except SystemExit: | ||
os._exit(0) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import glob | ||
import pika | ||
|
||
""""" | ||
import glob, os | ||
os.chdir("./") | ||
for file in glob.glob("*.pdf"): | ||
print(file) | ||
""" | ||
|
||
file = input("Enter your file name: ") | ||
|
||
connection = pika.BlockingConnection( | ||
pika.ConnectionParameters(host='localhost')) | ||
channel = connection.channel() | ||
|
||
channel.queue_declare(queue='sendPDF') | ||
|
||
|
||
channel.basic_publish(exchange='', routing_key='sendPDF', body=file) | ||
print(" [x] Sent 'A message getText'") | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pika, sys, os, PyPDF2 | ||
from transformers import pipeline | ||
|
||
|
||
def main(): | ||
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) | ||
channel = connection.channel() | ||
|
||
channel.queue_declare(queue='sendTxt') | ||
|
||
def callback(ch, method, properties, body): | ||
print(f" [x] Received {body}") | ||
print(body) | ||
|
||
|
||
|
||
channel.basic_consume(queue='sendTxt', on_message_callback=callback, auto_ack=True) | ||
|
||
print(' [*] Waiting for messages. To exit press CTRL+C') | ||
channel.start_consuming() | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
print('Interrupted') | ||
try: | ||
sys.exit(0) | ||
except SystemExit: | ||
os._exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sendPDF |