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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
import torch
|
5 |
+
import torch.nn as nn
|
6 |
+
import transformers
|
7 |
+
from transformers import AutoTokenizer, AutoConfig, LlamaForCausalLM, LlamaTokenizer, GenerationConfig, AutoModel, pipeline
|
8 |
+
import pandas as pd
|
9 |
+
import tensorflow as tf
|
10 |
+
import numpy as np
|
11 |
+
import math
|
12 |
+
import time
|
13 |
+
import csv
|
14 |
+
import nltk
|
15 |
+
from nltk.tokenize import word_tokenize
|
16 |
+
from nltk.corpus import stopwords
|
17 |
+
nltk.download('stopwords')
|
18 |
+
nltk.download('punkt')
|
19 |
+
import string
|
20 |
+
|
21 |
+
########### Import Classifier Embeddings #########
|
22 |
+
class_embeddings = pd.read_csv('Embeddings/MainClassEmbeddings.csv')
|
23 |
+
|
24 |
+
########### DATA CLEANER VARIABLES #############
|
25 |
+
all_stopwords = stopwords.words('english') # Making sure to only use English stopwords
|
26 |
+
extra_stopwords = ['ii', 'iii'] # Can add extra stopwords to be removed from dataset/input abstracts
|
27 |
+
all_stopwords.extend(extra_stopwords)
|
28 |
+
|
29 |
+
########### GET CLAIMED TRAINED MODEL ###########
|
30 |
+
tokenizer = LlamaTokenizer.from_pretrained("samwit/koala-7b")
|
31 |
+
|
32 |
+
model = LlamaForCausalLM.from_pretrained(
|
33 |
+
"samwit/koala-7b",
|
34 |
+
load_in_8bit=True,
|
35 |
+
device_map='auto',
|
36 |
+
)
|
37 |
+
|
38 |
+
########## DEFINING FUNCTIONS ###################
|
39 |
+
|
40 |
+
def mean_pooling(model_output, attention_mask):
|
41 |
+
token_embeddings = model_output[0]
|
42 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
43 |
+
return tf.reduce_sum(token_embeddings * input_mask_expanded, 1) / tf.clip_by_value(input_mask_expanded.sum(1), clip_value_min=1e-9, clip_value_max=math.inf)
|
44 |
+
|
45 |
+
def broad_scope_class_predictor(class_embeddings, abstract_embedding, SearchType, N=5, Sensitivity='Medium'):
|
46 |
+
predictions = pd.DataFrame(columns=['Class Name', 'Score'])
|
47 |
+
for i in range(len(class_embeddings)):
|
48 |
+
class_name = class_embeddings.iloc[i, 0]
|
49 |
+
embedding = class_embeddings.iloc[i, 2]
|
50 |
+
embedding = convert_saved_embeddings(embedding)
|
51 |
+
abstract_embedding = abstract_embedding.numpy()
|
52 |
+
abstract_embedding = torch.from_numpy(abstract_embedding)
|
53 |
+
cos = torch.nn.CosineSimilarity(dim=1)
|
54 |
+
score = cos(abstract_embedding, embedding).numpy().tolist()
|
55 |
+
result = [class_name, score[0]]
|
56 |
+
predictions.loc[len(predictions)] = result
|
57 |
+
if Sensitivity == 'High':
|
58 |
+
Threshold = 0.5
|
59 |
+
elif Sensitivity == 'Medium':
|
60 |
+
Threshold = 0.40
|
61 |
+
elif Sensitivity == 'Low':
|
62 |
+
Threshold = 0.35
|
63 |
+
GreenLikelihood = 'False'
|
64 |
+
HighestSimilarity = predictions.nlargest(N, ['Score'])
|
65 |
+
HighestSimilarity = HighestSimilarity['Class Name'].tolist()
|
66 |
+
HighestSimilarityClass = [x.split('/')[0] for x in HighestSimilarity]
|
67 |
+
if SearchType == 'Google Patent Search':
|
68 |
+
Links = [f'https://patents.google.com/?q=({x}%2f00)&oq={x}%2f00' for x in HighestSimilarityClass]
|
69 |
+
elif SearchType == 'Espacenet Patent Search':
|
70 |
+
Links = [f'https://worldwide.espacenet.com/patent/search?q=cpc%3D{x}%2F00%2Flow' for x in HighestSimilarityClass]
|
71 |
+
HighestSimilarity = pd.DataFrame({'Class':HighestSimilarity, 'Links':Links})
|
72 |
+
return HighestSimilarity
|
73 |
+
|
74 |
+
|
75 |
+
def sentence_embedder(sentences, model_path):
|
76 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path) #instantiating the sentence embedder using HuggingFace library
|
77 |
+
model = AutoModel.from_pretrained(model_path, from_tf=True) #making a model instance
|
78 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
79 |
+
# Compute token embeddings
|
80 |
+
with torch.no_grad():
|
81 |
+
model_output = model(**encoded_input)
|
82 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask']) #outputs a (1, 384) tensor representation of input text
|
83 |
+
return sentence_embeddings
|
84 |
+
|
85 |
+
|
86 |
+
def add_text(history, text):
|
87 |
+
history = history + [(text, None)]
|
88 |
+
return history, ""
|
89 |
+
|
90 |
+
|
91 |
+
def convert_saved_embeddings(embedding_string):
|
92 |
+
"""
|
93 |
+
Preparing pre-computed embeddings for use for comparison with new abstract embeddings .
|
94 |
+
Pre-computed embeddings are saved as tensors in string format so need to be converted back to numpy arrays in order to calculate cosine similarity.
|
95 |
+
:param embedding_string:
|
96 |
+
:return: Should be a single tensor with dims (,384) in string format
|
97 |
+
"""
|
98 |
+
embedding = embedding_string.replace('(', '')
|
99 |
+
embedding = embedding.replace(')', '')
|
100 |
+
embedding = embedding.replace('[', '')
|
101 |
+
embedding = embedding.replace(']', '')
|
102 |
+
embedding = embedding.replace('tensor', '')
|
103 |
+
embedding = embedding.replace(' ', '')
|
104 |
+
embedding = embedding.split(',')
|
105 |
+
embedding = [float(x) for x in embedding]
|
106 |
+
embedding = np.array(embedding)
|
107 |
+
embedding = np.expand_dims(embedding, axis=0)
|
108 |
+
embedding = torch.from_numpy(embedding)
|
109 |
+
return embedding
|
110 |
+
|
111 |
+
########## LOADING PRE-COMPUTED EMBEDDINGS ##########
|
112 |
+
|
113 |
+
def clean_data(input, type='Dataframe'):
|
114 |
+
if type == 'Dataframe':
|
115 |
+
cleaneddf = pd.DataFrame(columns=['Class', 'Description'])
|
116 |
+
for i in range(0, len(input)):
|
117 |
+
row_list = input.loc[i, :].values.flatten().tolist()
|
118 |
+
noNaN_row = [x for x in row_list if str(x) != 'nan']
|
119 |
+
listrow = []
|
120 |
+
if len(noNaN_row) > 0:
|
121 |
+
row = noNaN_row[:-1]
|
122 |
+
row = [x.strip() for x in row]
|
123 |
+
row = (" ").join(row)
|
124 |
+
text_tokens = word_tokenize(row) # splits abstracts into individual tokens to allow removal of stopwords by list comprehension
|
125 |
+
Stopword_Filtered_List = [word for word in text_tokens if not word in all_stopwords] # removes stopwords
|
126 |
+
row = (" ").join(Stopword_Filtered_List) # returns abstract to string form
|
127 |
+
removechars = ['[', ']', '{', '}', ';', '(', ')', ',', '.', ':', '/', '-', '#', '?', '@', '£', '$']
|
128 |
+
for char in removechars:
|
129 |
+
row = list(map(lambda x: x.replace(char, ''), row))
|
130 |
+
|
131 |
+
row = ''.join(row)
|
132 |
+
wnum = row.split(' ')
|
133 |
+
wnum = [x.lower() for x in wnum]
|
134 |
+
#remove duplicate words
|
135 |
+
wnum = list(dict.fromkeys(wnum))
|
136 |
+
#removing numbers
|
137 |
+
wonum = []
|
138 |
+
for x in wnum:
|
139 |
+
xv = list(x)
|
140 |
+
xv = [i.isnumeric() for i in xv]
|
141 |
+
if True in xv:
|
142 |
+
continue
|
143 |
+
else:
|
144 |
+
wonum.append(x)
|
145 |
+
row = ' '.join(wonum)
|
146 |
+
l = [noNaN_row[-1], row]
|
147 |
+
cleaneddf.loc[len(cleaneddf)] = l
|
148 |
+
cleaneddf = cleaneddf.drop_duplicates(subset=['Description'])
|
149 |
+
cleaneddf.to_csv('E:/Users/eeo21/Startup/CPC_Classifications_List/additionalcleanedclasses.csv', index=False)
|
150 |
+
return cleaneddf
|
151 |
+
|
152 |
+
elif type == 'String':
|
153 |
+
text_tokens = word_tokenize(input) # splits abstracts into individual tokens to allow removal of stopwords by list comprehension
|
154 |
+
Stopword_Filtered_List = [word for word in text_tokens if not word in all_stopwords] # removes stopwords
|
155 |
+
row = (" ").join(Stopword_Filtered_List) # returns abstract to string form
|
156 |
+
removechars = ['[', ']', '{', '}', ';', '(', ')', ',', '.', ':', '/', '-', '#', '?', '@', '£', '$']
|
157 |
+
for char in removechars:
|
158 |
+
row = list(map(lambda x: x.replace(char, ''), row))
|
159 |
+
row = ''.join(row)
|
160 |
+
wnum = row.split(' ')
|
161 |
+
wnum = [x.lower() for x in wnum]
|
162 |
+
# remove duplicate words
|
163 |
+
wnum = list(dict.fromkeys(wnum))
|
164 |
+
# removing numbers
|
165 |
+
wonum = []
|
166 |
+
for x in wnum:
|
167 |
+
xv = list(x)
|
168 |
+
xv = [i.isnumeric() for i in xv]
|
169 |
+
if True in xv:
|
170 |
+
continue
|
171 |
+
else:
|
172 |
+
wonum.append(x)
|
173 |
+
row = ' '.join(wonum)
|
174 |
+
return row
|
175 |
+
|
176 |
+
def classifier(userin, SearchType):
|
177 |
+
clean_in = clean_data(userin, type='String')
|
178 |
+
in_emb = sentence_embedder(clean_in, 'Model_bert')
|
179 |
+
|
180 |
+
Number = 10
|
181 |
+
broad_scope_predictions = broad_scope_class_predictor(class_embeddings, in_emb, SearchType, Number, Sensitivity='High')
|
182 |
+
|
183 |
+
class_links = []
|
184 |
+
for i in range(Number):
|
185 |
+
class_links.append("[[{}]]({})".format(broad_scope_predictions['Class'][i], broad_scope_predictions['Links'][i]))
|
186 |
+
|
187 |
+
|
188 |
+
md_class = '\n'.join(class_links)
|
189 |
+
|
190 |
+
return md_class
|
191 |
+
|
192 |
+
def generateresponse(history, temp, top_p, tokens):
|
193 |
+
|
194 |
+
global model
|
195 |
+
global tokenizer
|
196 |
+
|
197 |
+
user = history[-1][0]
|
198 |
+
|
199 |
+
PROMPT = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
200 |
+
### Instruction:
|
201 |
+
{user}
|
202 |
+
### Response:"""
|
203 |
+
|
204 |
+
pipe = pipeline(
|
205 |
+
"text-generation",
|
206 |
+
model=model,
|
207 |
+
tokenizer=tokenizer,
|
208 |
+
max_length=tokens,
|
209 |
+
temperature=temp,
|
210 |
+
top_p=top_p,
|
211 |
+
repetition_penalty=1.15
|
212 |
+
)
|
213 |
+
|
214 |
+
outputs = pipe(PROMPT)
|
215 |
+
outputs = outputs[0]['generated_text']
|
216 |
+
outputs = str(outputs).split('### Response')[1]
|
217 |
+
|
218 |
+
response = f"Response{outputs}"
|
219 |
+
return response
|
220 |
+
|
221 |
+
def run_model(userin, dropd, temp, top_p, tokens):
|
222 |
+
|
223 |
+
global model
|
224 |
+
global tokenizer
|
225 |
+
|
226 |
+
if dropd in ["An apparatus", "A method of use", "A method", "A method of making", "A system"]:
|
227 |
+
PROMPT = claim_selector(userin, dropd)
|
228 |
+
elif dropd in ["Generate a Detailed Description Paragraph", "Generate a Abstract", "What are the Benefits/Technical Effects"]:
|
229 |
+
PROMPT = desc_selector(userin, dropd)
|
230 |
+
|
231 |
+
pipe = pipeline(
|
232 |
+
"text-generation",
|
233 |
+
model=model,
|
234 |
+
tokenizer=tokenizer,
|
235 |
+
max_length=tokens,
|
236 |
+
temperature=temp,
|
237 |
+
top_p=top_p,
|
238 |
+
repetition_penalty=1.15
|
239 |
+
)
|
240 |
+
|
241 |
+
outputs = pipe(PROMPT)
|
242 |
+
|
243 |
+
outputs = outputs[0]['generated_text']
|
244 |
+
outputs = str(outputs).split('### Response')[1]
|
245 |
+
outputs = outputs.split('\n \n \n \n*')[0]
|
246 |
+
|
247 |
+
response = f"Response{outputs}"
|
248 |
+
return response
|
249 |
+
|
250 |
+
def prosecute(application, priorart, temp, top_p, tokens):
|
251 |
+
|
252 |
+
global model
|
253 |
+
global tokenizer
|
254 |
+
|
255 |
+
pipe = pipeline(
|
256 |
+
"text-generation",
|
257 |
+
model=model,
|
258 |
+
tokenizer=tokenizer,
|
259 |
+
max_length=tokens,
|
260 |
+
temperature=temp,
|
261 |
+
top_p=top_p,
|
262 |
+
repetition_penalty=1.15
|
263 |
+
)
|
264 |
+
|
265 |
+
PROMPT = f"""
|
266 |
+
Draft an argument for the patentability in favour of the application using the European Patent Office Problem Solution. Start by summarising the difference between the application and the prior art:
|
267 |
+
|
268 |
+
Application: {application}
|
269 |
+
|
270 |
+
Prior Art: {priorart}
|
271 |
+
|
272 |
+
### Response: The objective technical problem solved by the present invention"""
|
273 |
+
|
274 |
+
outputs = pipe(PROMPT)
|
275 |
+
|
276 |
+
outputs = outputs[0]['generated_text']
|
277 |
+
outputs = str(outputs).split('### Response')[1]
|
278 |
+
outputs = outputs.split('\n \n \n \n*')[0]
|
279 |
+
|
280 |
+
response = f"Response{outputs}"
|
281 |
+
return response
|
282 |
+
|
283 |
+
def ideator(userin, temp, top_p, tokens):
|
284 |
+
|
285 |
+
global model
|
286 |
+
global tokenizer
|
287 |
+
|
288 |
+
pipe = pipeline(
|
289 |
+
"text-generation",
|
290 |
+
model=model,
|
291 |
+
tokenizer=tokenizer,
|
292 |
+
max_length=tokens,
|
293 |
+
temperature=temp,
|
294 |
+
top_p=top_p,
|
295 |
+
repetition_penalty=1.15
|
296 |
+
)
|
297 |
+
|
298 |
+
PROMPT = f"""
|
299 |
+
How can I make {userin}
|
300 |
+
|
301 |
+
### Response: You could implement the invention as follows:"""
|
302 |
+
|
303 |
+
outputs = pipe(PROMPT)
|
304 |
+
|
305 |
+
outputs = outputs[0]['generated_text']
|
306 |
+
outputs = str(outputs).split('### Response')[1]
|
307 |
+
outputs = outputs.split('\n \n \n \n*')[0]
|
308 |
+
|
309 |
+
|
310 |
+
response = f"Response{outputs}"
|
311 |
+
return response
|
312 |
+
|
313 |
+
def Chat(userin, temp, top_p, tokens):
|
314 |
+
|
315 |
+
global model
|
316 |
+
global tokenizer
|
317 |
+
|
318 |
+
pipe = pipeline(
|
319 |
+
"text-generation",
|
320 |
+
model=model,
|
321 |
+
tokenizer=tokenizer,
|
322 |
+
max_length=tokens,
|
323 |
+
temperature=temp,
|
324 |
+
top_p=top_p,
|
325 |
+
repetition_penalty=1.15
|
326 |
+
)
|
327 |
+
|
328 |
+
PROMPT = f"""Below is a query from a user. Respond appropriately to the query.
|
329 |
+
### Query:
|
330 |
+
{userin}
|
331 |
+
### Response:"""
|
332 |
+
|
333 |
+
outputs = pipe(PROMPT)
|
334 |
+
|
335 |
+
outputs = outputs[0]['generated_text']
|
336 |
+
outputs = str(outputs).split('### Response')[1]
|
337 |
+
outputs = outputs.split('\n \n \n \n*')[0]
|
338 |
+
|
339 |
+
response = f"Response{outputs}"
|
340 |
+
return response
|
341 |
+
|
342 |
+
def claim_selector(userin, dropd):
|
343 |
+
|
344 |
+
PROMPT = f"""
|
345 |
+
Draft a patent claim 1 for {dropd} for the following invention: {userin}
|
346 |
+
### Response:{dropd} comprising:"""
|
347 |
+
|
348 |
+
return PROMPT
|
349 |
+
|
350 |
+
def desc_selector(userin, dropd):
|
351 |
+
|
352 |
+
PROMPT = f"""
|
353 |
+
{dropd} for a patent application for the following invention: {userin}
|
354 |
+
### Response:"""
|
355 |
+
|
356 |
+
return PROMPT
|
357 |
+
|
358 |
+
############# GRADIO APP ###############
|
359 |
+
|
360 |
+
theme = gr.themes.Base(
|
361 |
+
primary_hue="indigo",
|
362 |
+
).set(
|
363 |
+
prose_text_size='*text_sm'
|
364 |
+
)
|
365 |
+
|
366 |
+
with gr.Blocks(title='Claimed', theme=theme) as demo:
|
367 |
+
gr.Markdown("""
|
368 |
+
# CLAIMED - A GENERATIVE TOOLKIT FOR PATENT ATTORNEYS AND INVENTORS
|
369 |
+
The patenting process can be complex, time-consuming and expensive. We believe that AI will one day solve these problems.
|
370 |
+
|
371 |
+
Welcome to our demo! We've trained Meta's Llama on over 200k entries, with a focus on tasks related to the intellectual property domain.
|
372 |
+
Please note that this is for research purposes and shouldn't be used commercially.
|
373 |
+
None of the outputs of this model, taken in part or in its entirety, constitutes legal advice. If you are seeking protection for you intellectual property, consult a registered patent/trademark attorney.
|
374 |
+
""")
|
375 |
+
|
376 |
+
with gr.Tab("Ideator"):
|
377 |
+
gr.Markdown("""
|
378 |
+
Use this tool to generate ideas!
|
379 |
+
""")
|
380 |
+
with gr.Row(scale=1, min_width=600):
|
381 |
+
with gr.Column():
|
382 |
+
userin = gr.Text(label="Input", lines=5)
|
383 |
+
with gr.Column():
|
384 |
+
text2 = gr.Textbox(label="Output", lines=5)
|
385 |
+
with gr.Row():
|
386 |
+
btn = gr.Button("Submit")
|
387 |
+
with gr.Row():
|
388 |
+
with gr.Accordion("Parameters"):
|
389 |
+
temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
390 |
+
top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
391 |
+
tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
392 |
+
|
393 |
+
btn.click(fn=ideator, inputs=[userin, temp, top_p, tokens], outputs=text2)
|
394 |
+
|
395 |
+
with gr.Tab("Claim Drafter"):
|
396 |
+
gr.Markdown("""
|
397 |
+
Use this tool to expand your idea into the technical language of a patent claim. You can specify the type of claim you want using the dropdown menu.
|
398 |
+
""")
|
399 |
+
Claimchoices = gr.Dropdown(["An apparatus", "A method of use", "A method", "A method of making", "A system"], label='Choose Claim Type Here')
|
400 |
+
|
401 |
+
with gr.Row(scale=1, min_width=600):
|
402 |
+
text1 = gr.Textbox(label="Input",
|
403 |
+
placeholder='Type in your idea here!', lines=5)
|
404 |
+
text2 = gr.Textbox(label="Output", lines=5)
|
405 |
+
with gr.Row():
|
406 |
+
btn = gr.Button("Submit")
|
407 |
+
with gr.Row():
|
408 |
+
with gr.Accordion("Parameters"):
|
409 |
+
temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
410 |
+
top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
411 |
+
tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
412 |
+
|
413 |
+
btn.click(fn=claim_selector, inputs=[text1, Claimchoices]).then(run_model, inputs=[text1, Claimchoices, temp, top_p, tokens], outputs=text2)
|
414 |
+
|
415 |
+
with gr.Tab("Description Generator"):
|
416 |
+
gr.Markdown("""
|
417 |
+
Use this tool to expand your patent claim into a description. You can also use this tool to generate abstracts and give you ideas about the benefit of an invention by changing the settings in the dropdown menu.
|
418 |
+
""")
|
419 |
+
Descriptionchoices = gr.Dropdown(["Generate a Detailed Description Paragraph", "Generate a Abstract", "What are the Benefits/Technical Effects"], label='Choose Generation Type Here')
|
420 |
+
with gr.Row(scale=1, min_width=600):
|
421 |
+
|
422 |
+
text1 = gr.Textbox(label="Input",
|
423 |
+
placeholder='Type in your idea here!', lines=5)
|
424 |
+
text2 = gr.Textbox(label="Output", lines=5)
|
425 |
+
with gr.Row():
|
426 |
+
btn = gr.Button("Submit")
|
427 |
+
with gr.Row():
|
428 |
+
with gr.Accordion("Parameters"):
|
429 |
+
temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
430 |
+
top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
431 |
+
tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
432 |
+
|
433 |
+
btn.click(fn=desc_selector, inputs=[text1, Descriptionchoices]).then(run_model, inputs=[text1, Descriptionchoices, temp, top_p, tokens], outputs=text2)
|
434 |
+
|
435 |
+
with gr.Tab("Prosecution Beta"):
|
436 |
+
gr.Markdown("""
|
437 |
+
Use this tool to generate ideas for how to overcome objections to novelty and inventive step. For now, this tool only works on relatively short inputs, so maybe try with some simple claims or short paragraphs.
|
438 |
+
""")
|
439 |
+
with gr.Row(scale=1, min_width=600):
|
440 |
+
with gr.Column():
|
441 |
+
application = gr.Text(label="Present Invention", lines=5)
|
442 |
+
priorart = gr.Text(label="Prior Art Document", lines=5)
|
443 |
+
with gr.Column():
|
444 |
+
text2 = gr.Textbox(label="Output", lines=5)
|
445 |
+
with gr.Row():
|
446 |
+
btn = gr.Button("Submit")
|
447 |
+
|
448 |
+
with gr.Row():
|
449 |
+
with gr.Accordion("Parameters"):
|
450 |
+
temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
451 |
+
top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
452 |
+
tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
453 |
+
|
454 |
+
btn.click(fn=prosecute, inputs=[application, priorart, temp, top_p, tokens], outputs=text2)
|
455 |
+
|
456 |
+
with gr.Tab("CPC Search Tool"):
|
457 |
+
gr.Markdown("""
|
458 |
+
Use this tool to classify your invention according to the Cooperative Patent Classification system.
|
459 |
+
Click on the link to initiate either an Espacenet or Google Patents classification search using the generated classifications. You can specify which you would like using the dropdown menu.
|
460 |
+
""")
|
461 |
+
|
462 |
+
ClassifyChoices = gr.Dropdown(["Google Patent Search", "Espacenet Patent Search"], label='Choose Search Type Here')
|
463 |
+
with gr.Row(scale=1, min_width=600):
|
464 |
+
with gr.Column(scale=5):
|
465 |
+
userin = gr.Textbox(label="Input", placeholder='Type in your Claim/Description/Abstract Here',lines=5)
|
466 |
+
with gr.Column(scale=1):
|
467 |
+
with gr.Accordion("CPC classes"):
|
468 |
+
output = gr.Markdown() #gr.Textbox(label="Output", lines=5)
|
469 |
+
with gr.Row():
|
470 |
+
classify_btn = gr.Button("Classify")
|
471 |
+
classify_btn.click(fn=classifier, inputs=[userin, ClassifyChoices] , outputs=output)
|
472 |
+
|
473 |
+
|
474 |
+
with gr.Tab("Chat"):
|
475 |
+
gr.Markdown("""
|
476 |
+
Do you want a bit more freedom over the outputs you generate? No problem! You can use a chatbot version of our model below. You can ask it anything.
|
477 |
+
If you're concerned about a particular output, hit the flag button and we will use that information to improve the model.
|
478 |
+
""")
|
479 |
+
with gr.Row(scale=1, min_width=600):
|
480 |
+
with gr.Column():
|
481 |
+
userin = gr.Text(label="Question", lines=5)
|
482 |
+
with gr.Column():
|
483 |
+
text2 = gr.Textbox(label="Answer", lines=5)
|
484 |
+
with gr.Row():
|
485 |
+
btn = gr.Button("Submit")
|
486 |
+
|
487 |
+
with gr.Row():
|
488 |
+
with gr.Accordion("Parameters"):
|
489 |
+
temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
490 |
+
top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
491 |
+
tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
492 |
+
btn.click(fn=Chat, inputs=[userin, temp, top_p, tokens], outputs=text2)
|
493 |
+
|
494 |
+
# gr.Markdown("""
|
495 |
+
# # THE CHATBOT
|
496 |
+
# Do you want a bit more freedom over the outputs you generate? No problem! You can use a chatbot version of our model below. You can ask it anything.
|
497 |
+
# If you're concerned about a particular output, hit the flag button and we will use that information to improve the model.
|
498 |
+
# """)
|
499 |
+
|
500 |
+
# chatbot = gr.Chatbot([], elem_id="Claimed Assistant").style(height=500)
|
501 |
+
# with gr.Row():
|
502 |
+
# with gr.Column(scale=1):
|
503 |
+
# txt = gr.Textbox(
|
504 |
+
# show_label=False,
|
505 |
+
# placeholder="Enter text and submit",
|
506 |
+
# ).style(container=False)
|
507 |
+
#
|
508 |
+
# with gr.Row():
|
509 |
+
# with gr.Accordion("Parameters"):
|
510 |
+
# temp = gr.Slider(minimum=0, maximum=1, value=0.6, label="Temperature", step=0.1)
|
511 |
+
# top_p = gr.Slider(minimum=0.5, maximum=1, value=0.95, label="Top P", step=0.1)
|
512 |
+
# tokens = gr.Slider(minimum=5, maximum=1024, value=256, label="Max Tokens", step=1)
|
513 |
+
#
|
514 |
+
# txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
|
515 |
+
# generateresponse, [chatbot, temp, top_p, tokens], chatbot)
|
516 |
+
|
517 |
+
gr.Markdown("""
|
518 |
+
# HAVE AN IDEA? GET IT CLAIMED
|
519 |
+
In the future, we are looking to expand our model's capabilities further to assist in a range of IP related tasks.
|
520 |
+
If you are interested in using a more powerful model that we have trained, or if you have any suggestions of features you would like to see us add, please get in touch!
|
521 |
+
As far as data is concerned, you have nothing to worry about! We don't store any of your inputs to use for further training, we're not OpenAI.
|
522 |
+
|
523 |
+
""")
|
524 |
+
demo.queue(max_size=15)
|
525 |
+
demo.launch(share=True)
|