Spaces:
Sleeping
Sleeping
Add Streamlit app for patentability score prediction
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
6 |
+
import torch
|
7 |
+
|
8 |
+
# Load model and tokenizer
|
9 |
+
model_path = "rb757/new_app"
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
12 |
+
|
13 |
+
# Load the dataset
|
14 |
+
dataset_url = "https://huggingface.co/datasets/HUPD/hupd/resolve/main/hupd_metadata_2022-02-22.feather"
|
15 |
+
df = pd.read_feather(dataset_url)
|
16 |
+
|
17 |
+
# Title and description
|
18 |
+
st.title("Milestone Patent 🐨")
|
19 |
+
st.write("Select a patent application to evaluate its patentability.")
|
20 |
+
|
21 |
+
# Dropdown for application filing numbers
|
22 |
+
application_numbers = df['application_number'].unique()
|
23 |
+
selected_application = st.selectbox("Select Application Filing Number", application_numbers)
|
24 |
+
|
25 |
+
# Retrieve abstract and claims
|
26 |
+
if selected_application:
|
27 |
+
patent_info = df[df['application_number'] == selected_application].iloc[0]
|
28 |
+
abstract = patent_info['abstract']
|
29 |
+
claims = patent_info['claims']
|
30 |
+
|
31 |
+
# Display the abstract and claims
|
32 |
+
st.text_area("Abstract", abstract, height=150)
|
33 |
+
st.text_area("Claims", claims, height=150)
|
34 |
+
|
35 |
+
# Submit button
|
36 |
+
if st.button("Get Patentability Score"):
|
37 |
+
# Prepare the input text
|
38 |
+
input_text = f"{abstract} {claims}"
|
39 |
+
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
40 |
+
|
41 |
+
# Get the model prediction
|
42 |
+
with torch.no_grad():
|
43 |
+
logits = model(**inputs).logits
|
44 |
+
predictions = torch.argmax(logits, dim=-1)
|
45 |
+
|
46 |
+
# Display the patentability score
|
47 |
+
decision_labels = ['REJECTED', 'ACCEPTED', 'PENDING', 'CONT-REJECTED', 'CONT-ACCEPTED', 'CONT-PENDING']
|
48 |
+
score = decision_labels[predictions.item()]
|
49 |
+
st.write(f"Patentability Score: **{score}**")
|