Spaces:
Runtime error
Runtime error
Commit
·
716c6e6
1
Parent(s):
a3f4fd4
Update app.py
Browse files
app.py
CHANGED
@@ -232,6 +232,68 @@ def generateresponse(history):#, task):
|
|
232 |
print(history)
|
233 |
return history
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
############# GRADIO APP ###############
|
236 |
|
237 |
theme = gr.themes.Base(
|
@@ -259,12 +321,15 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
259 |
gr.Markdown("""
|
260 |
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.
|
261 |
""")
|
262 |
-
gr.Dropdown(["Apparatus Claim", "Method of Use Claim", "Method Claim", ], label='Choose Claim Type Here')
|
263 |
|
264 |
with gr.Row(scale=1, min_width=600):
|
265 |
text1 = gr.Textbox(label="Input",
|
266 |
placeholder='Type in your idea here!')
|
267 |
text2 = gr.Textbox(label="Output")
|
|
|
|
|
|
|
268 |
|
269 |
with gr.Tab("Description Generator"):
|
270 |
gr.Markdown("""
|
@@ -276,6 +341,9 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
276 |
text1 = gr.Textbox(label="Input",
|
277 |
placeholder='Type in your idea here!')
|
278 |
text2 = gr.Textbox(label="Output")
|
|
|
|
|
|
|
279 |
|
280 |
# with gr.Tab("Knowledge Graph"):
|
281 |
# gr.Markdown("""
|
|
|
232 |
print(history)
|
233 |
return history
|
234 |
|
235 |
+
|
236 |
+
def run_model(userin, dropd):
|
237 |
+
|
238 |
+
global model
|
239 |
+
global tokenizer
|
240 |
+
|
241 |
+
if dropd in ["Apparatus Claim", "Method of Use Claim", "Method Claim"]:
|
242 |
+
PROMPT = claim_selector(userin, dropd)
|
243 |
+
elif dropd in ["Generate Description", "Generate Abstract", "Benefits of the invention"]:
|
244 |
+
PROMPT = desc_selector(userin, dropd)
|
245 |
+
|
246 |
+
inputs = tokenizer(
|
247 |
+
PROMPT,
|
248 |
+
return_tensors="pt",
|
249 |
+
)
|
250 |
+
input_ids = inputs["input_ids"].cuda()
|
251 |
+
|
252 |
+
generation_config = GenerationConfig(
|
253 |
+
temperature=0.6,
|
254 |
+
top_p=0.95,
|
255 |
+
repetition_penalty=1.15,
|
256 |
+
)
|
257 |
+
print("Generating...")
|
258 |
+
generation_output = model.generate(
|
259 |
+
input_ids=input_ids,
|
260 |
+
generation_config=generation_config,
|
261 |
+
return_dict_in_generate=True,
|
262 |
+
output_scores=True,
|
263 |
+
max_new_tokens=256,
|
264 |
+
)
|
265 |
+
output = []
|
266 |
+
for s in generation_output.sequences:
|
267 |
+
output.append(tokenizer.decode(s))
|
268 |
+
print(tokenizer.decode(s))
|
269 |
+
|
270 |
+
outputs = (output[0].split('### Response:'))[1]
|
271 |
+
|
272 |
+
response = f"Response: {outputs}"
|
273 |
+
|
274 |
+
return response
|
275 |
+
|
276 |
+
def claim_selector(userin, dropd):
|
277 |
+
|
278 |
+
PROMPT = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
279 |
+
### Instruction:
|
280 |
+
Draft a patent claim 1 for {dropd} comprising {userin}
|
281 |
+
### Response:"""
|
282 |
+
|
283 |
+
return PROMPT
|
284 |
+
|
285 |
+
def desc_selector(userin, dropd):
|
286 |
+
|
287 |
+
PROMPT = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
288 |
+
### Instruction:
|
289 |
+
{dropd} for {userin}
|
290 |
+
### Response:"""
|
291 |
+
|
292 |
+
return PROMPT
|
293 |
+
|
294 |
+
|
295 |
+
|
296 |
+
|
297 |
############# GRADIO APP ###############
|
298 |
|
299 |
theme = gr.themes.Base(
|
|
|
321 |
gr.Markdown("""
|
322 |
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.
|
323 |
""")
|
324 |
+
choices = gr.Dropdown(["Apparatus Claim", "Method of Use Claim", "Method Claim", ], label='Choose Claim Type Here')
|
325 |
|
326 |
with gr.Row(scale=1, min_width=600):
|
327 |
text1 = gr.Textbox(label="Input",
|
328 |
placeholder='Type in your idea here!')
|
329 |
text2 = gr.Textbox(label="Output")
|
330 |
+
with gr.Row():
|
331 |
+
btn = gr.Button("submit")
|
332 |
+
btn.click(fn=claim_selector, inputs=[text1, choices]).then(run_model, inputs=[text1, choices], outputs=text2)
|
333 |
|
334 |
with gr.Tab("Description Generator"):
|
335 |
gr.Markdown("""
|
|
|
341 |
text1 = gr.Textbox(label="Input",
|
342 |
placeholder='Type in your idea here!')
|
343 |
text2 = gr.Textbox(label="Output")
|
344 |
+
with gr.Row():
|
345 |
+
btn = gr.Button("submit")
|
346 |
+
btn.click(fn=desc_selector, inputs=[text1, choices]).then(run_model, inputs=[text1, choices], outputs=text2)
|
347 |
|
348 |
# with gr.Tab("Knowledge Graph"):
|
349 |
# gr.Markdown("""
|