Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (37 loc) · 1.09 KB

File metadata and controls

45 lines (37 loc) · 1.09 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import socket
import json
from scripts import SentimentAnalysisModel
# Configuration
HOST = '127.0.0.1'
PORT = 5000
BUFFER_SIZE = 1024
# Load the model
model = SentimentAnalysisModel()
# Create a socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
# Listen for connections
server_socket.listen()
print(f"Listening on port {PORT}...")
# Accept a connection
client_socket, address = server_socket.accept()
print(f"Accepted connection from {address}.")
try:
while True:
data = client_socket.recv(BUFFER_SIZE).decode("utf-8")
if not data:
break
print(f"Received data from client: {data}")
# Make a prediction
result = model.predict(data)
# Send the result back to the client
result_json = json.dumps(result)
client_socket.sendall(result_json.encode("utf-8"))
print(f"Sent prediction to client: {result_json}")
except Exception as e:
print(e)
finally:
# Close the connection
client_socket.close()
server_socket.close()
print("Connection closed.")
Morty Proxy This is a proxified and sanitized view of the page, visit original site.