Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
4 |
import json
|
|
|
|
|
5 |
|
6 |
access_token = os.environ['ACCES_TOKEN']
|
7 |
|
@@ -20,8 +22,19 @@ classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, m
|
|
20 |
adibideak = json.load(open("./Adibideak.json", "r"))
|
21 |
|
22 |
def prozesatu(Testua, request: gr.Request):
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
prediction = prozesatu.classifier(Testua)[0]
|
26 |
if prediction["label"]=="GAI":
|
27 |
return {"Gai":prediction["score"], "Ez gai": 1-prediction["score"]}
|
|
|
2 |
import os
|
3 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
4 |
import json
|
5 |
+
import socket
|
6 |
+
from datetime import datetime
|
7 |
|
8 |
access_token = os.environ['ACCES_TOKEN']
|
9 |
|
|
|
22 |
adibideak = json.load(open("./Adibideak.json", "r"))
|
23 |
|
24 |
def prozesatu(Testua, request: gr.Request):
|
25 |
+
client_ip = request.client.host
|
26 |
+
local_ip = socket.gethostbyname(socket.gethostbyname(""))
|
27 |
+
headers = request.kwargs['headers']
|
28 |
+
if headers and 'x-forwarded-for' in headers:
|
29 |
+
x_forwarded_for = headers['x-forwarded-for']
|
30 |
+
client_ip = x_forwarded_for.split(' ')[0] if x_forwarded_for else ""
|
31 |
+
|
32 |
+
f = open("Erabiltzaileak.txt", "a")
|
33 |
+
|
34 |
+
f.write(f'Erabiltzailea: {client_ip}. Eguna eta ordua: {now}.\n')
|
35 |
+
|
36 |
+
f.close()
|
37 |
+
|
38 |
prediction = prozesatu.classifier(Testua)[0]
|
39 |
if prediction["label"]=="GAI":
|
40 |
return {"Gai":prediction["score"], "Ez gai": 1-prediction["score"]}
|