DrishtiSharma commited on
Commit
5633d52
·
verified ·
1 Parent(s): dfbdb14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -50
app.py CHANGED
@@ -51,48 +51,10 @@ The response should be formatted as a structured JSON object, as shown below:
51
  // Additional measurements
52
  ]
53
  }
54
- ### Example:
55
- If the patent discusses "A novel RF power amplifier operating at 2.4 GHz with a bandwidth of 20 MHz and an output power of 30 dBm," the output should be:
56
- {
57
- "Patent_Title": "High-Efficiency RF Power Amplifier",
58
- "Patent_Abstract": "A novel RF power amplifier with improved impedance matching for wireless communication devices.",
59
- "Patent_Metadata": {
60
- "Patent_Number": "US12345678B2",
61
- "Filing_Date": "2024-06-20",
62
- "Inventors": ["Jane Doe", "John Smith"],
63
- "Assignee": "TechWave Inc."
64
- },
65
- "Content": [
66
- {
67
- "Measurement_substance": "RF power amplifier",
68
- "Measured_value": "2.4",
69
- "Measured_unit": "GHz",
70
- "measurement_type": "operating frequency"
71
- },
72
- {
73
- "Measurement_substance": "RF power amplifier",
74
- "Measured_value": "20",
75
- "Measured_unit": "MHz",
76
- "measurement_type": "bandwidth"
77
- },
78
- {
79
- "Measurement_substance": "RF power amplifier",
80
- "Measured_value": "30",
81
- "Measured_unit": "dBm",
82
- "measurement_type": "output power"
83
- }
84
- ]
85
- }
86
- ### Key Considerations:
87
- - Extract as much detailed information as possible based on the text.
88
- - Retain accuracy: Avoid inferring data not explicitly mentioned.
89
- - Follow the structured JSON format strictly for consistency.
90
- - Exclude any irrelevant or redundant information. Focus only on RF and related hardware technical data.
91
  """
92
 
93
-
94
  # Title and description
95
- st.title("Technical Measurements Extractor for Patents")
96
  st.write(
97
  "Analyze patents to extract physical measurements such as frequency, bandwidth, and more. "
98
  "Provide a date range to download patents and analyze them using GPT models."
@@ -113,10 +75,35 @@ model_choice = st.selectbox(
113
 
114
  logging_enabled = st.checkbox("Enable logging?", value=False, help="Toggle logging for debugging purposes.")
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  # Run Analysis Button
117
  if st.button("Analyze Patents"):
118
  if not start_date_input or not end_date_input:
119
  st.error("Please enter both start and end dates!")
 
 
 
 
120
  else:
121
  try:
122
  # Parse date inputs
@@ -138,8 +125,18 @@ if st.button("Analyze Patents"):
138
  st.stop()
139
  st.success(f"{len(saved_patent_names)} patents found and processed!")
140
 
141
- # Step 2: Analyze patents using GPT
142
- random_patents = saved_patent_names[:num_patents_to_analyze]
 
 
 
 
 
 
 
 
 
 
143
  total_cost = 0
144
  results = []
145
 
@@ -147,18 +144,13 @@ if st.button("Analyze Patents"):
147
  for i, patent_file in enumerate(random_patents):
148
  cost, output = qa_agent.call_QA_to_json(
149
  PROMPT,
150
- start_date.year, # Pass start_date year, month, and day
151
- start_date.month,
152
- start_date.day,
153
- saved_patent_names,
154
- i,
155
- logging_enabled,
156
- model_choice,
157
  )
158
  total_cost += cost
159
  results.append(output)
160
 
161
- # Step 3: Display results
162
  st.write(f"**Total Cost:** ${total_cost:.4f}")
163
  st.write("### Analysis Results:")
164
  for idx, result in enumerate(results):
@@ -168,4 +160,4 @@ if st.button("Analyze Patents"):
168
  except ValueError as ve:
169
  st.error(f"Invalid date format: {ve}")
170
  except Exception as e:
171
- st.error(f"An unexpected error occurred: {e}")
 
51
  // Additional measurements
52
  ]
53
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  """
55
 
 
56
  # Title and description
57
+ st.title("Blah")
58
  st.write(
59
  "Analyze patents to extract physical measurements such as frequency, bandwidth, and more. "
60
  "Provide a date range to download patents and analyze them using GPT models."
 
75
 
76
  logging_enabled = st.checkbox("Enable logging?", value=False, help="Toggle logging for debugging purposes.")
77
 
78
+ # Keyword Management
79
+ st.header("Manage Keywords")
80
+ st.write("Add or delete keywords for filtering patents.")
81
+ default_keywords = [
82
+ "RF", "Radio Frequency", "Wireless Communication", "Antenna", "Microwave", "Electromagnetic Waves",
83
+ "Beamforming", "5G", "6G", "Patch Antenna", "Dipole Antenna", "Phased Array", "Radiation Pattern", "IoT",
84
+ "Wireless Charging"
85
+ ]
86
+ keywords_input = st.text_area(
87
+ "Enter keywords for filtering (comma-separated):", value=", ".join(default_keywords)
88
+ )
89
+ user_keywords = [kw.strip() for kw in keywords_input.split(",") if kw.strip()]
90
+
91
+ # Field Selection
92
+ st.header("Choose Fields for Filtering")
93
+ fields = st.multiselect(
94
+ "Select fields to search for keywords:",
95
+ ["Title", "Abstract", "Claims", "Summary", "Detailed Description"],
96
+ default=["Title", "Abstract"]
97
+ )
98
+
99
  # Run Analysis Button
100
  if st.button("Analyze Patents"):
101
  if not start_date_input or not end_date_input:
102
  st.error("Please enter both start and end dates!")
103
+ elif not user_keywords:
104
+ st.error("Please provide at least one keyword for filtering.")
105
+ elif not fields:
106
+ st.error("Please select at least one field for filtering.")
107
  else:
108
  try:
109
  # Parse date inputs
 
125
  st.stop()
126
  st.success(f"{len(saved_patent_names)} patents found and processed!")
127
 
128
+ # Step 2: Filter patents based on user input
129
+ with st.spinner("Filtering patents..."):
130
+ filtered_patents = preprocess_data.filter_rf_patents(
131
+ saved_patent_names, keywords=user_keywords, fields=fields
132
+ )
133
+ if not filtered_patents:
134
+ st.error("No patents matched the filtering criteria.")
135
+ st.stop()
136
+ st.success(f"{len(filtered_patents)} relevant patents found and processed!")
137
+
138
+ # Step 3: Analyze patents using GPT
139
+ random_patents = filtered_patents[:num_patents_to_analyze]
140
  total_cost = 0
141
  results = []
142
 
 
144
  for i, patent_file in enumerate(random_patents):
145
  cost, output = qa_agent.call_QA_to_json(
146
  PROMPT,
147
+ start_date.year, start_date.month, start_date.day,
148
+ saved_patent_names, i, logging_enabled, model_choice
 
 
 
 
 
149
  )
150
  total_cost += cost
151
  results.append(output)
152
 
153
+ # Step 4: Display results
154
  st.write(f"**Total Cost:** ${total_cost:.4f}")
155
  st.write("### Analysis Results:")
156
  for idx, result in enumerate(results):
 
160
  except ValueError as ve:
161
  st.error(f"Invalid date format: {ve}")
162
  except Exception as e:
163
+ st.error(f"An unexpected error occurred: {e}")