EkhiAzur commited on
Commit
43da25f
1 Parent(s): 8269c48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
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
- if Testua[-3:]=="...":
24
- Testua = prozesatu.adibideak[Testua]
 
 
 
 
 
 
 
 
 
 
 
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"]}