Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
libs/python/kafka/consumer.py
CHANGED
|
@@ -32,7 +32,27 @@ class KafkaConsumerWrapper:
|
|
| 32 |
ca = os.environ.get('KAFKA_SSL_CA_LOCATION')
|
| 33 |
cert = os.environ.get('KAFKA_SSL_CERT_LOCATION')
|
| 34 |
key = os.environ.get('KAFKA_SSL_KEY_LOCATION')
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
self.conf.update({
|
| 37 |
'security.protocol': 'SSL',
|
| 38 |
'ssl.ca.location': ca,
|
|
|
|
| 32 |
ca = os.environ.get('KAFKA_SSL_CA_LOCATION')
|
| 33 |
cert = os.environ.get('KAFKA_SSL_CERT_LOCATION')
|
| 34 |
key = os.environ.get('KAFKA_SSL_KEY_LOCATION')
|
| 35 |
+
|
| 36 |
+
# If files don't exist (like on HF Space), check for raw PEM strings and create temp files
|
| 37 |
+
if not (ca and os.path.exists(ca)):
|
| 38 |
+
ca_pem = os.environ.get('KAFKA_SSL_CA') or os.environ.get('KAFKA_SSL_CA_PEM')
|
| 39 |
+
if ca_pem:
|
| 40 |
+
ca = '/tmp/ca.pem'
|
| 41 |
+
with open(ca, 'w') as f: f.write(ca_pem)
|
| 42 |
+
|
| 43 |
+
if not (cert and os.path.exists(cert)):
|
| 44 |
+
cert_pem = os.environ.get('KAFKA_SSL_CERT') or os.environ.get('KAFKA_SSL_CERT_PEM')
|
| 45 |
+
if cert_pem:
|
| 46 |
+
cert = '/tmp/service.cert'
|
| 47 |
+
with open(cert, 'w') as f: f.write(cert_pem)
|
| 48 |
+
|
| 49 |
+
if not (key and os.path.exists(key)):
|
| 50 |
+
key_pem = os.environ.get('KAFKA_SSL_KEY') or os.environ.get('KAFKA_SSL_KEY_PEM')
|
| 51 |
+
if key_pem:
|
| 52 |
+
key = '/tmp/service.key'
|
| 53 |
+
with open(key, 'w') as f: f.write(key_pem)
|
| 54 |
+
|
| 55 |
+
if ca and cert and key and os.path.exists(ca) and os.path.exists(cert) and os.path.exists(key):
|
| 56 |
self.conf.update({
|
| 57 |
'security.protocol': 'SSL',
|
| 58 |
'ssl.ca.location': ca,
|
libs/python/kafka/producer.py
CHANGED
|
@@ -15,11 +15,31 @@ class KafkaProducerWrapper:
|
|
| 15 |
def __init__(self, bootstrap_servers: str = "localhost:9092"):
|
| 16 |
conf = {'bootstrap.servers': bootstrap_servers}
|
| 17 |
|
| 18 |
-
#
|
| 19 |
ca = os.environ.get('KAFKA_SSL_CA_LOCATION')
|
| 20 |
cert = os.environ.get('KAFKA_SSL_CERT_LOCATION')
|
| 21 |
key = os.environ.get('KAFKA_SSL_KEY_LOCATION')
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
conf.update({
|
| 24 |
'security.protocol': 'SSL',
|
| 25 |
'ssl.ca.location': ca,
|
|
|
|
| 15 |
def __init__(self, bootstrap_servers: str = "localhost:9092"):
|
| 16 |
conf = {'bootstrap.servers': bootstrap_servers}
|
| 17 |
|
| 18 |
+
# Try finding physical files first
|
| 19 |
ca = os.environ.get('KAFKA_SSL_CA_LOCATION')
|
| 20 |
cert = os.environ.get('KAFKA_SSL_CERT_LOCATION')
|
| 21 |
key = os.environ.get('KAFKA_SSL_KEY_LOCATION')
|
| 22 |
+
|
| 23 |
+
# If files don't exist (like on HF Space), check for raw PEM strings and create temp files
|
| 24 |
+
if not (ca and os.path.exists(ca)):
|
| 25 |
+
ca_pem = os.environ.get('KAFKA_SSL_CA') or os.environ.get('KAFKA_SSL_CA_PEM')
|
| 26 |
+
if ca_pem:
|
| 27 |
+
ca = '/tmp/ca.pem'
|
| 28 |
+
with open(ca, 'w') as f: f.write(ca_pem)
|
| 29 |
+
|
| 30 |
+
if not (cert and os.path.exists(cert)):
|
| 31 |
+
cert_pem = os.environ.get('KAFKA_SSL_CERT') or os.environ.get('KAFKA_SSL_CERT_PEM')
|
| 32 |
+
if cert_pem:
|
| 33 |
+
cert = '/tmp/service.cert'
|
| 34 |
+
with open(cert, 'w') as f: f.write(cert_pem)
|
| 35 |
+
|
| 36 |
+
if not (key and os.path.exists(key)):
|
| 37 |
+
key_pem = os.environ.get('KAFKA_SSL_KEY') or os.environ.get('KAFKA_SSL_KEY_PEM')
|
| 38 |
+
if key_pem:
|
| 39 |
+
key = '/tmp/service.key'
|
| 40 |
+
with open(key, 'w') as f: f.write(key_pem)
|
| 41 |
+
|
| 42 |
+
if ca and cert and key and os.path.exists(ca) and os.path.exists(cert) and os.path.exists(key):
|
| 43 |
conf.update({
|
| 44 |
'security.protocol': 'SSL',
|
| 45 |
'ssl.ca.location': ca,
|
libs/python/schemas/sentiment_result.py
CHANGED
|
@@ -19,6 +19,7 @@ class SentimentResult(BaseModel):
|
|
| 19 |
|
| 20 |
# Metadata
|
| 21 |
model_name: str = Field("xlm-roberta-sentiment", description="Name of the model used")
|
|
|
|
| 22 |
processed_at: datetime = Field(default_factory=datetime.utcnow, description="UTC timestamp of processing")
|
| 23 |
|
| 24 |
class Config:
|
|
|
|
| 19 |
|
| 20 |
# Metadata
|
| 21 |
model_name: str = Field("xlm-roberta-sentiment", description="Name of the model used")
|
| 22 |
+
metadata: dict = Field(default_factory=dict)
|
| 23 |
processed_at: datetime = Field(default_factory=datetime.utcnow, description="UTC timestamp of processing")
|
| 24 |
|
| 25 |
class Config:
|