Spaces:
Paused
Paused
first update
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from datasets import load_dataset, Dataset
|
| 3 |
from collections import defaultdict
|
| 4 |
import random
|
|
|
|
| 5 |
|
| 6 |
# Load the source dataset
|
| 7 |
source_dataset = load_dataset("vietdata/eng_echo", split="train")
|
|
@@ -11,15 +12,28 @@ source_texts = source_dataset["query"]
|
|
| 11 |
translations = defaultdict(list)
|
| 12 |
processed_data = []
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Helper function to get the next text for translation
|
| 15 |
def get_next_text(user_id):
|
| 16 |
# Filter texts that already have 10 translations
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
# Select a random eligible text for translation
|
| 22 |
-
next_text = random.choice(
|
| 23 |
return next_text
|
| 24 |
|
| 25 |
# Function to handle translation submission
|
|
@@ -71,8 +85,9 @@ user_sessions = {}
|
|
| 71 |
|
| 72 |
def login(username, state):
|
| 73 |
state[0] = username
|
|
|
|
| 74 |
# Authenticate user
|
| 75 |
-
if
|
| 76 |
#user_sessions[username] = True
|
| 77 |
return f"Welcome, {username}!", gr.update(visible=False), gr.update(visible=True), get_next_text(username)
|
| 78 |
else:
|
|
|
|
| 2 |
from datasets import load_dataset, Dataset
|
| 3 |
from collections import defaultdict
|
| 4 |
import random
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
# Load the source dataset
|
| 8 |
source_dataset = load_dataset("vietdata/eng_echo", split="train")
|
|
|
|
| 12 |
translations = defaultdict(list)
|
| 13 |
processed_data = []
|
| 14 |
|
| 15 |
+
def authenticate(user_id):
|
| 16 |
+
|
| 17 |
+
url = "https://intern-api.imtaedu.com/api/subnets/2/authenticate"
|
| 18 |
+
headers = {
|
| 19 |
+
"Content-Type": "application/json",
|
| 20 |
+
"Accept": "application/json",
|
| 21 |
+
"X-Public-Api-Key": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
|
| 22 |
+
}
|
| 23 |
+
payload = { "token": "NPldirErwCHb6ZB5NZ9WW0UDmlr3jxxJ" }
|
| 24 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 25 |
+
|
| 26 |
+
return response.status_code == 200
|
| 27 |
+
|
| 28 |
# Helper function to get the next text for translation
|
| 29 |
def get_next_text(user_id):
|
| 30 |
# Filter texts that already have 10 translations
|
| 31 |
+
eligible_texts = [text for text in source_texts if len(translations[text]) < 10]
|
| 32 |
+
if not eligible_texts:
|
| 33 |
+
return "All texts are fully translated."
|
| 34 |
|
| 35 |
# Select a random eligible text for translation
|
| 36 |
+
next_text = random.choice(eligible_texts)
|
| 37 |
return next_text
|
| 38 |
|
| 39 |
# Function to handle translation submission
|
|
|
|
| 85 |
|
| 86 |
def login(username, state):
|
| 87 |
state[0] = username
|
| 88 |
+
|
| 89 |
# Authenticate user
|
| 90 |
+
if authenticate(username):
|
| 91 |
#user_sessions[username] = True
|
| 92 |
return f"Welcome, {username}!", gr.update(visible=False), gr.update(visible=True), get_next_text(username)
|
| 93 |
else:
|