ravimohan19 commited on
Commit
cb4d01a
Β·
verified Β·
1 Parent(s): 7b161f7

Upload models.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. models.py +124 -0
models.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Pydantic models and state definitions for the Polymer Datasheet Agent.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import uuid
8
+ from datetime import datetime
9
+ from typing import Any, Literal, Optional
10
+
11
+ from pydantic import BaseModel, Field
12
+
13
+
14
+ # ── LangGraph State ──────────────────────────────────────────────────────────
15
+
16
+ class AgentState(BaseModel):
17
+ """State that flows through the LangGraph workflow."""
18
+
19
+ # Input
20
+ input_mode: Literal["search", "upload"] = "search"
21
+ manufacturer: str = ""
22
+ polymer_family: str = ""
23
+ grade: str = ""
24
+ uploaded_text: str = "" # Raw text from uploaded PDF/file
25
+
26
+ # Search phase
27
+ search_queries: list[str] = Field(default_factory=list)
28
+ search_results: list[dict[str, Any]] = Field(default_factory=list)
29
+ raw_content: str = "" # Aggregated raw text from web/upload
30
+
31
+ # Parsing phase
32
+ parsed_datasheet: Optional[DatasheetRecord] = None
33
+ parsing_errors: list[str] = Field(default_factory=list)
34
+
35
+ # Output
36
+ status: str = "pending"
37
+ message: str = ""
38
+
39
+
40
+ # ── Datasheet Record ─────────────────────────────────────────────────────────
41
+
42
+ class DatasheetRecord(BaseModel):
43
+ """A single parsed polymer datasheet stored in the database."""
44
+
45
+ id: str = Field(default_factory=lambda: str(uuid.uuid4()))
46
+ created_at: str = Field(default_factory=lambda: datetime.now().isoformat())
47
+
48
+ # General
49
+ material_name: str = ""
50
+ trade_name: str = ""
51
+ manufacturer: str = ""
52
+ polymer_family: str = ""
53
+ grade: str = ""
54
+ description: str = ""
55
+ processing_method: str = ""
56
+ features: str = ""
57
+ applications: str = ""
58
+ source_url: str = ""
59
+
60
+ # Mechanical
61
+ tensile_strength_mpa: str = ""
62
+ tensile_modulus_mpa: str = ""
63
+ elongation_at_break_pct: str = ""
64
+ flexural_strength_mpa: str = ""
65
+ flexural_modulus_mpa: str = ""
66
+ impact_strength_charpy_kj_m2: str = ""
67
+ impact_strength_izod_j_m: str = ""
68
+ hardness_shore_d: str = ""
69
+ hardness_rockwell: str = ""
70
+ compressive_strength_mpa: str = ""
71
+
72
+ # Thermal
73
+ melting_temperature_c: str = ""
74
+ glass_transition_temperature_c: str = ""
75
+ heat_deflection_temperature_c: str = ""
76
+ vicat_softening_temperature_c: str = ""
77
+ continuous_service_temperature_c: str = ""
78
+ thermal_conductivity_w_mk: str = ""
79
+ coefficient_of_thermal_expansion_um_mk: str = ""
80
+ flammability_rating: str = ""
81
+
82
+ # Physical
83
+ density_g_cm3: str = ""
84
+ melt_flow_index_g_10min: str = ""
85
+ water_absorption_pct: str = ""
86
+ moisture_absorption_pct: str = ""
87
+ specific_gravity: str = ""
88
+ transparency: str = ""
89
+ color: str = ""
90
+
91
+ # Electrical
92
+ dielectric_strength_kv_mm: str = ""
93
+ dielectric_constant: str = ""
94
+ volume_resistivity_ohm_cm: str = ""
95
+ surface_resistivity_ohm: str = ""
96
+ dissipation_factor: str = ""
97
+
98
+ # Chemical Resistance
99
+ acid_resistance: str = ""
100
+ alkali_resistance: str = ""
101
+ solvent_resistance: str = ""
102
+ uv_resistance: str = ""
103
+ weatherability: str = ""
104
+
105
+ # Regulatory
106
+ fda_approved: str = ""
107
+ rohs_compliant: str = ""
108
+ reach_compliant: str = ""
109
+ ul94_rating: str = ""
110
+
111
+ def to_flat_dict(self) -> dict[str, str]:
112
+ """Return all fields as a flat dict for database storage."""
113
+ return self.model_dump()
114
+
115
+
116
+ # ── Search Result ────────────────────────────────────────────────────────────
117
+
118
+ class SearchResult(BaseModel):
119
+ """One web search result from Tavily."""
120
+ title: str = ""
121
+ url: str = ""
122
+ content: str = ""
123
+ raw_content: str = ""
124
+ score: float = 0.0