Spaces:
Runtime error
Runtime error
Commit
·
4f0174e
1
Parent(s):
c20cbe8
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the fine-tuned model and tokenizer
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("slachitoff/CS-GY_6613_Milestone_3")
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained("slachitoff/CS-GY_6613_Milestone_3")
|
9 |
+
|
10 |
+
# Define the app layout
|
11 |
+
st.set_page_config(page_title="Patentability Classifier App")
|
12 |
+
st.title("Patentability Classifier")
|
13 |
+
st.markdown("Enter the Patent ID, abstract and claims:")
|
14 |
+
|
15 |
+
# Define SessionState to store patent scores and ideas within the session
|
16 |
+
class SessionState:
|
17 |
+
def __init__(self):
|
18 |
+
self.patentData = {
|
19 |
+
"1234567890": {
|
20 |
+
"abstract": "A system and method for monitoring and predicting patient health is disclosed. The system utilizes a wearable device that collects data from various sensors, including heart rate, blood pressure, and oxygen saturation. The collected data is analyzed by a machine learning algorithm to predict health issues, such as heart attacks or strokes, before they occur.",
|
21 |
+
"claims": "A method for predicting patient health comprising: collecting data from a wearable device comprising a plurality of sensors that measure heart rate, blood pressure, and oxygen saturation; and analyzing said collected data using a machine learning algorithm to predict potential health issues."
|
22 |
+
},
|
23 |
+
"2345678901": {
|
24 |
+
"abstract": "A software application for real-time translation and transcription of audio recordings is disclosed. The application comprises a speech recognition module that transcribes audio recordings in one language and a machine translation module that translates the transcribed text into another language.",
|
25 |
+
"claims": "A software application for real-time translation and transcription of audio recordings comprising: a speech recognition module configured to transcribe audio recordings in a first language; and a machine translation module configured to translate said transcribed text into a second language."
|
26 |
+
},
|
27 |
+
"3456789012": {
|
28 |
+
"abstract": "A system and method for energy management in commercial buildings is disclosed. The system utilizes a combination of sensors, energy storage devices, and control algorithms to monitor and optimize energy consumption. The system is designed to reduce energy waste and improve the efficiency of HVAC and lighting systems in commercial buildings.",
|
29 |
+
"claims": "A system for energy management in commercial buildings comprising: a plurality of sensors configured to measure temperature, humidity, and occupancy levels; an energy storage device configured to store excess energy generated by HVAC and lighting systems; and a control algorithm configured to optimize energy consumption based on data from said sensors."
|
30 |
+
},
|
31 |
+
"4567890123": {
|
32 |
+
"abstract": "An electric vehicle with improved range and performance is disclosed. The vehicle comprises a regenerative braking system that converts kinetic energy into electrical energy during braking and a power management system that utilizes the stored energy during acceleration. The regenerative braking system improves the vehicle's overall efficiency and extends its range.",
|
33 |
+
"claims": "An electric vehicle with improved range and performance comprising: a regenerative braking system configured to convert kinetic energy into electrical energy during braking and store said electrical energy in a battery; and a power management system configured to provide said stored electrical energy to an electric motor during acceleration to improve the vehicle's performance and extend its range."
|
34 |
+
},
|
35 |
+
"5678901234": {
|
36 |
+
"abstract": "A device for preventing pets from accessing restricted areas is disclosed. The device comprises a motion sensor that detects when a pet enters a restricted area and emits a high-pitched sound to deter the pet from entering. The device is designed to be easily installed and can be used to keep pets away from certain rooms or pieces of furniture.",
|
37 |
+
"claims": "A pet deterrent device comprising: a motion sensor configured to detect when a pet enters a restricted area; and a speaker configured to emit a high-pitched sound to deter said pet from entering said restricted area."
|
38 |
+
},
|
39 |
+
"6789012345": {
|
40 |
+
"abstract": "A system for tracking the location of personal belongings is disclosed. The system utilizes a combination of RFID tags and a mobile application to track the location of personal items, such as keys or wallets. The mobile application can be used to view the location of the tracked items and receive notifications when they are moved or taken outside of a certain range.",
|
41 |
+
"claims": "A system for tracking personal belongings comprising: a plurality of RFID tags configured to be attached to personal items; a mobile application configured to communicate with said RFID tags and display the location of said personal items; and a notification system configured to notify a user when said personal items are moved or taken outside of a certain range."
|
42 |
+
},
|
43 |
+
"7890123456": {
|
44 |
+
"abstract": "A device for filtering and purifying air is disclosed. The device comprises a HEPA filter and an activated carbon filter that work together to remove pollutants and allergens from the air. The device is designed to be compact and portable, making it ideal for use in small spaces such as offices or bedrooms.",
|
45 |
+
"claims": "An air purifying device comprising: a HEPA filter configured to remove pollutants and allergens from the air; and an activated carbon filter configured to remove odors and other harmful substances from the air."
|
46 |
+
},
|
47 |
+
"8901234567": {
|
48 |
+
"abstract": "A device for making coffee is disclosed. The device comprises a container for holding water, a coffee filter for holding ground coffee, and a heating element for heating the water. The device is designed to be easy to use and can make a single cup of coffee at a time.",
|
49 |
+
"claims": "A coffee-making device comprising: a container for holding water; a coffee filter for holding ground coffee; and a heating element configured to heat said water and pass it through said coffee filter to make coffee."
|
50 |
+
},
|
51 |
+
"9012345678": {
|
52 |
+
"abstract": "A software application for tracking daily exercise is disclosed. The application allows users to input their daily exercise routines and track their progress over time. The application also includes social features that allow users to connect with friends and share their progress.",
|
53 |
+
"claims": "A software application for tracking daily exercise comprising: a user interface configured to allow users to input their daily exercise routines; a tracking system configured to record said exercise routines and display progress over time; and a social network feature configured to allow users to connect with friends and share their progress."
|
54 |
+
},
|
55 |
+
"0123456789": {
|
56 |
+
"abstract": "A device for holding books is disclosed. The device comprises a stand with adjustable arms that can hold books of various sizes. The device is designed to be portable and can be used in a variety of settings, such as in bed or on a table.",
|
57 |
+
"claims": "A book holder device comprising: a stand with adjustable arms configured to hold books of various sizes, and a base configured to provide stability to said stand."
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
state = SessionState()
|
62 |
+
|
63 |
+
# Define the function to calculate the patentability score
|
64 |
+
@st.cache_data()
|
65 |
+
def calculateScore(patent_id, abstract, claims):
|
66 |
+
inputs = tokenizer(abstract, claims, padding=True, truncation=True, max_length=512, return_tensors='pt')
|
67 |
+
outputs = model(**inputs)
|
68 |
+
logits = outputs.logits
|
69 |
+
scores = logits.softmax(dim=1).tolist()[0]
|
70 |
+
score, idx = np.max(scores), np.argmax(scores)
|
71 |
+
certainty = score*100
|
72 |
+
decision = 'Patentable' if idx==1 else 'Not Patentable'
|
73 |
+
return {'Abstract': abstract, 'Claims': claims, 'Decision': decision, 'Certainty': certainty}
|
74 |
+
|
75 |
+
|
76 |
+
# Define the patent IDs
|
77 |
+
patentIds = ["1234567890", "2345678901", "3456789012", "4567890123", "5678901234",
|
78 |
+
"6789012345", "7890123456", "8901234567", "9012345678", "0123456789"]
|
79 |
+
|
80 |
+
# Define the dropdown menu for the patent ID
|
81 |
+
selectedPatentId = st.selectbox("Select Patent ID", patentIds)
|
82 |
+
|
83 |
+
# Autofill the Abstract and Claims text boxes based on the selected patent ID
|
84 |
+
if selectedPatentId != "":
|
85 |
+
abstractText = state.patentData[selectedPatentId]["abstract"]
|
86 |
+
claimsText = state.patentData[selectedPatentId]["claims"]
|
87 |
+
else:
|
88 |
+
abstractText = ""
|
89 |
+
claimsText = ""
|
90 |
+
|
91 |
+
# Define the text area widgets for abstract and claims
|
92 |
+
abstractText = st.text_area("Abstract", height=200, value=abstractText)
|
93 |
+
claimsText = st.text_area("Claims", height=200, value=claimsText)
|
94 |
+
|
95 |
+
# Define the submit button for patent ideas and scores
|
96 |
+
if st.button("Submit"):
|
97 |
+
if not abstractText.strip() or not claimsText.strip():
|
98 |
+
st.write("Please enter the abstract and claims.")
|
99 |
+
else:
|
100 |
+
scoreData = calculateScore(selectedPatentId, abstractText, claimsText)
|
101 |
+
patentData = {'Abstract': abstractText, 'Claims': claimsText, 'Score': scoreData}
|
102 |
+
state.patentData[selectedPatentId] = patentData
|
103 |
+
st.write("Patent ID:", selectedPatentId)
|
104 |
+
st.write("Abstract:", abstractText)
|
105 |
+
st.write("Claims:", claimsText)
|
106 |
+
st.write("Patentability Score:", scoreData['Decision'])
|
107 |
+
st.write("Certainty (%):", scoreData['Certainty'])
|