Update app.py
Browse files
app.py
CHANGED
@@ -32,14 +32,24 @@ def init_client():
|
|
32 |
return None, str(e)
|
33 |
|
34 |
def classify_text(client, text_content):
|
35 |
-
"""Classify text using Google Cloud Natural Language API"""
|
36 |
try:
|
37 |
document = language_v1.Document(
|
38 |
content=text_content,
|
39 |
type_=language_v1.Document.Type.PLAIN_TEXT
|
40 |
)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
categories = response.categories
|
44 |
|
45 |
results = []
|
|
|
32 |
return None, str(e)
|
33 |
|
34 |
def classify_text(client, text_content):
|
35 |
+
"""Classify text using Google Cloud Natural Language API with V2 model"""
|
36 |
try:
|
37 |
document = language_v1.Document(
|
38 |
content=text_content,
|
39 |
type_=language_v1.Document.Type.PLAIN_TEXT
|
40 |
)
|
41 |
|
42 |
+
# Configure V2 model options for better performance
|
43 |
+
classification_model_options = language_v1.ClassificationModelOptions(
|
44 |
+
v2_model=language_v1.ClassificationModelOptions.V2Model()
|
45 |
+
)
|
46 |
+
|
47 |
+
response = client.classify_text(
|
48 |
+
request={
|
49 |
+
'document': document,
|
50 |
+
'classification_model_options': classification_model_options
|
51 |
+
}
|
52 |
+
)
|
53 |
categories = response.categories
|
54 |
|
55 |
results = []
|