File size: 3,259 Bytes
9148f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1100717
 
 
9148f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1100717
 
 
 
9148f34
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";

let currentRoast = "";
let currentUsername = "";

async function checkUser(username) {
  try {
    const response = await fetch(
      `https://huggingface.co/api/users/${username}/overview`
    );
    return { valid: response.ok };
  } catch {
    return { valid: false };
  }
}

async function roastUser() {
  const username = document.getElementById("username-input").value.trim();
  const language = document.getElementById("language-select").value;
  const errorBox = document.getElementById("error-box");
  const roastBtn = document.getElementById("roast-btn");
  const roastContainer = document.getElementById("roast-container");
  const roastText = document.getElementById("roast-text");

  errorBox.style.display = "none";
  roastContainer.style.display = "none";

  if (!username) {
    errorBox.textContent = "Please provide a username";
    errorBox.style.display = "block";
    return;
  }

  roastBtn.disabled = true;
  roastBtn.textContent = "Roasting in progress...";
  roastBtn.classList.add("animate-pulse");

  const userCheck = await checkUser(username);
  if (!userCheck.valid) {
    errorBox.textContent = `User '${username}' not found on Hugging Face`;
    errorBox.style.display = "block";
    roastBtn.disabled = false;
    roastBtn.textContent = "Roast this Hugger 🔥";
    roastBtn.classList.remove("animate-pulse");
    return;
  }

  try {
    const client = await Client.connect("nroggendorff/hugger-roaster-gradio", {
      hf_token: "hf_token",
    });
    const result = await client.predict("/roast_user", [username, language]);

    currentRoast = result.data[0];
    currentUsername = username;

    if (
      currentRoast.startsWith("Error") ||
      currentRoast.startsWith("User") ||
      currentRoast.startsWith("Please")
    ) {
      errorBox.textContent = "⚠️ " + currentRoast;
      errorBox.style.display = "block";
    } else {
      roastText.textContent = currentRoast;
      roastContainer.style.display = "block";
      document.getElementById("share-output").style.display = "none";
    }
  } catch (error) {
    errorBox.textContent = "⚠️ Error generating roast: " + error.message;
    errorBox.style.display = "block";
  }

  roastBtn.disabled = false;
  roastBtn.textContent = "Roast this Hugger 🔥";
  roastBtn.classList.remove("animate-pulse");
}

async function shareRoast() {
  const shareBtn = document.getElementById("share-btn");
  const shareOutput = document.getElementById("share-output");

  shareBtn.disabled = true;
  shareBtn.classList.add("animate-pulse");

  try {
    const client = await Client.connect("nroggendorff/hugger-roaster-gradio", {
      hf_token: "hf_token",
    });
    const result = { data: ["Not Implemented."] };

    shareOutput.textContent = result.data[0];
    shareOutput.style.display = "block";
  } catch (error) {
    shareOutput.textContent = "Error sharing roast: " + error.message;
    shareOutput.style.display = "block";
  }

  shareBtn.disabled = false;
  shareBtn.classList.remove("animate-pulse");
}

document.getElementById("roast-btn").addEventListener("click", roastUser);
document.getElementById("share-btn").addEventListener("click", shareRoast);