bkhalaf commited on
Commit
1ecf838
·
1 Parent(s): 630bd43

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from transformers import pipeline, AutoModelWithLMHead, AutoTokenizer
5
+ import torch
6
+ import boto3
7
+
8
+ s3 = boto3.resource('s3')
9
+ s3_object = s3.Bucket('nlp-gpt-models').Object('mod_v1.pth').get()
10
+
11
+
12
+
13
+ st.title('Patent Context Generation Tool-Development Stage..')
14
+ model_path = s3_object
15
+ #model_path = 'https://nlp-gpt-models.s3.amazonaws.com/mod_v1.pth'
16
+ #model_path = 'https://drive.google.com/file/d/1-Dqk6fZzDiFKTqnnQ2yqW48uJk-CPqrB/view?usp=sharing'
17
+ propmt_title = st.text_input('Enter Your Title....', 'Biology...')
18
+
19
+ f1 = st.button('Generate')
20
+ if f1:
21
+ try:
22
+ saved_model = torch.load(model_path)
23
+ tokenizer = AutoTokenizer.from_pretrained("gpt2")
24
+ generator = pipeline('text-generation', model = saved_model , tokenizer = tokenizer)
25
+ def paraphrase(propmt_title):
26
+ p = generator('<s>' + propmt_title + '</s>>>>><p>')
27
+ return p[0]['generated_text'].split('</s>>>>>><p>')[0].split('</p>')[0].split('<p>')[1]
28
+ output= paraphrase(propmt_title)
29
+ st.text_area('paraphrased_titless', output ,False)
30
+ except Exception as e:
31
+ st.exception("Exception: %s\n" % e)
32
+ st.text_area('paraphrased_titless', st.exception("Exception: %s\n" % e) ,False)
33
+
34
+ propmt_title = st.text_input('Enter Your Paraphrased Title....', 'title context...')
35
+ f2 = st.form("my_form2")
36
+ f2.form_submit_button("Submit")
37
+
38
+ st.text_area('Generated Fields', '',False)
39
+
40
+
41
+ propmt_title = st.text_input('Enter Your Generated Field ....', 'Field context...')
42
+ f3 = st.form("my_form3")
43
+ f3.form_submit_button("Submit")
44
+
45
+ st.text_area('Generated Abstract', '',False)
46
+
47
+
48
+ propmt_title = st.text_input('Enter Your Generated Abstract ....', 'Abstract context...')
49
+ f4 = st.form("my_form4")
50
+ f4.form_submit_button("Submit")
51
+
52
+ st.text_area('Generated Background', '',False)
53
+
54
+
55
+
56
+ st.download_button(label="Download Full Patent (PDF file)",
57
+ data=propmt_title,
58
+ file_name="test.pdf",
59
+ mime='application/octet-stream')