Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from typing import List, Dict, Any, Optional, Union
|
| 2 |
-
from pydantic import BaseModel, Field,
|
| 3 |
import logging
|
| 4 |
from pathlib import Path
|
| 5 |
import json
|
|
@@ -62,8 +62,9 @@ class AgentState(BaseModel):
|
|
| 62 |
confidence_score: float = 0.0
|
| 63 |
memory: Dict[str, Any] = Field(default_factory=dict) # Persistent memory across steps
|
| 64 |
|
| 65 |
-
@
|
| 66 |
-
|
|
|
|
| 67 |
if not 0 <= v <= 1:
|
| 68 |
raise ValueError("Confidence score must be between 0 and 1")
|
| 69 |
return v
|
|
@@ -85,8 +86,9 @@ class Question(BaseModel):
|
|
| 85 |
metadata: Dict[str, Any] = Field(default_factory=dict)
|
| 86 |
priority: int = Field(default=1, ge=1, le=5)
|
| 87 |
|
| 88 |
-
@
|
| 89 |
-
|
|
|
|
| 90 |
if not v or not v.strip():
|
| 91 |
raise ValueError("Question text cannot be empty")
|
| 92 |
return v.strip()
|
|
@@ -114,8 +116,9 @@ class Answer(BaseModel):
|
|
| 114 |
timestamp: datetime = Field(default_factory=datetime.now)
|
| 115 |
metadata: Dict[str, Any] = Field(default_factory=dict)
|
| 116 |
|
| 117 |
-
@
|
| 118 |
-
|
|
|
|
| 119 |
if not 0 <= v <= 1:
|
| 120 |
raise ValueError("Confidence must be between 0 and 1")
|
| 121 |
return v
|
|
@@ -744,4 +747,16 @@ app = gr.mount_gradio_app(app, demo, path="/")
|
|
| 744 |
|
| 745 |
if __name__ == "__main__":
|
| 746 |
import uvicorn
|
| 747 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from typing import List, Dict, Any, Optional, Union
|
| 2 |
+
from pydantic import BaseModel, Field, field_validator
|
| 3 |
import logging
|
| 4 |
from pathlib import Path
|
| 5 |
import json
|
|
|
|
| 62 |
confidence_score: float = 0.0
|
| 63 |
memory: Dict[str, Any] = Field(default_factory=dict) # Persistent memory across steps
|
| 64 |
|
| 65 |
+
@field_validator('confidence_score')
|
| 66 |
+
@classmethod
|
| 67 |
+
def validate_confidence(cls, v: float) -> float:
|
| 68 |
if not 0 <= v <= 1:
|
| 69 |
raise ValueError("Confidence score must be between 0 and 1")
|
| 70 |
return v
|
|
|
|
| 86 |
metadata: Dict[str, Any] = Field(default_factory=dict)
|
| 87 |
priority: int = Field(default=1, ge=1, le=5)
|
| 88 |
|
| 89 |
+
@field_validator('text')
|
| 90 |
+
@classmethod
|
| 91 |
+
def validate_text(cls, v: str) -> str:
|
| 92 |
if not v or not v.strip():
|
| 93 |
raise ValueError("Question text cannot be empty")
|
| 94 |
return v.strip()
|
|
|
|
| 116 |
timestamp: datetime = Field(default_factory=datetime.now)
|
| 117 |
metadata: Dict[str, Any] = Field(default_factory=dict)
|
| 118 |
|
| 119 |
+
@field_validator('confidence')
|
| 120 |
+
@classmethod
|
| 121 |
+
def validate_confidence(cls, v: float) -> float:
|
| 122 |
if not 0 <= v <= 1:
|
| 123 |
raise ValueError("Confidence must be between 0 and 1")
|
| 124 |
return v
|
|
|
|
| 747 |
|
| 748 |
if __name__ == "__main__":
|
| 749 |
import uvicorn
|
| 750 |
+
|
| 751 |
+
# Configure uvicorn logging
|
| 752 |
+
log_config = uvicorn.config.LOGGING_CONFIG
|
| 753 |
+
log_config["formatters"]["access"]["fmt"] = "%(asctime)s - %(levelname)s - %(message)s"
|
| 754 |
+
|
| 755 |
+
# Run the server with explicit host and port
|
| 756 |
+
uvicorn.run(
|
| 757 |
+
app,
|
| 758 |
+
host="0.0.0.0",
|
| 759 |
+
port=7860,
|
| 760 |
+
log_config=log_config,
|
| 761 |
+
log_level="info"
|
| 762 |
+
)
|