jnjj commited on
Commit
c3f429d
·
verified ·
1 Parent(s): 7139b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -1
app.py CHANGED
@@ -34,7 +34,7 @@ TEXT_GENERATION_RATE = 40000
34
  html_code = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI Text Generation Platform</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" /><style>body {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;background: linear-gradient(to right, #667eea, #764ba2);color: #fff;margin: 0;padding: 0;overflow: hidden;display: flex;justify-content: center;align-items: center;min-height: 100vh;}.container {width: 80%;max-width: 900px;margin: 50px auto;background: rgba(255, 255, 255, 0.1);padding: 40px;border-radius: 15px;box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.2);transition: transform 0.3s ease-in-out;}.container:hover {transform: translateY(-5px);}.header {text-align: center;margin-bottom: 40px;color: #fff;}.header h1 {font-size: 3.5em;font-weight: 600;letter-spacing: 1px;text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);}.header p {font-size: 1.2em;opacity: 0.8;text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);}.form-group {margin-bottom: 30px;}.form-group label {display: block;margin-bottom: 10px;font-size: 1.1em;font-weight: 500;opacity: 0.9;text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);}.form-group textarea, .form-group input[type="text"] {width: 100%;padding: 15px;border: none;border-radius: 8px;background: rgba(255, 255, 255, 0.2);color: #fff;font-size: 16px;box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);backdrop-filter: blur(8px);transition: all 0.3s ease;}.form-group textarea:focus, .form-group input[type="text"]:focus {outline: none;background: rgba(255, 255, 255, 0.3);box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.3);}button {width: 100%;padding: 15px;border: none;border-radius: 8px;background: linear-gradient(to right, #43cea2, #185a9d);color: #fff;font-size: 18px;font-weight: 500;cursor: pointer;box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);transition: background 0.3s ease;position: relative;overflow: hidden;}button:hover {background: linear-gradient(to left, #43cea2, #185a9d);}button::before {content: '\\f021';font-family: FontAwesome;position: absolute;top: 0;left: -30px;width: 30px;height: 100%;background: rgba(255, 255, 255, 0.3);display: flex;align-items: center;justify-content: center;transition: left 0.4s ease;}button:hover::before {left: 100%;transform: translateX(-100%);}.animated-text {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);font-size: 6em;font-weight: bold;color: rgba(255, 255, 255, 0.05);pointer-events: none;z-index: -1;}#output {margin-top: 40px;padding: 25px;border-radius: 10px;background: rgba(255, 255, 255, 0.1);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.2);white-space: pre-wrap;word-break: break-word;opacity: 0;transition: opacity 1s ease, transform 0.5s ease;transform: translateY(20px);}#output.show {opacity: 1;transform: translateY(0);}#output strong {color: #93b8c2;font-weight: 600;}@keyframes fadeIn {from {opacity: 0;transform: translateY(-20px);}to {opacity: 1;transform: translateY(0);}}</style></head><body><div class="animated-text animate__animated animate__fadeIn animate__infinite infinite">AI POWERED</div><div class="container"><div class="header animate__animated animate__fadeInDown"><h1>AI Text Generation Platform</h1><p>Unleash your creativity with our advanced text generation tool.</p></div><div class="form-group animate__animated animate__fadeInLeft"><label for="text">Input Text:</label><textarea id="text" rows="5" placeholder="Enter your text here"></textarea></div><div class="form-group animate__animated animate__fadeInRight"><label for="length">Length:</label><input type="text" id="length" value="50" placeholder="Enter desired length"></div><div class="form-group animate__animated animate__fadeInLeft"><label for="temperature">Temperature:</label><input type="text" id="temperature" value="0.7" placeholder="Enter temperature (0-1)"></div><div class="form-group animate__animated animate__fadeInRight"><label for="top_k">Top K:</label><input type="text" id="top_k" value="40" placeholder="Enter top K value"></div><button onclick="generateText()" class="animate__animated animate__fadeInUp">Generate Text</button><div id="output" class="animate__animated"><strong >Generated Text:</strong><br><span id="generatedText"></span><br><br><strong >Reasoning:</strong><br><span id="reasoning"></span><br><br><strong >Category:</strong><br><span id="category"></span></div></div><script>async function generateText() {const inputText = document.getElementById("text").value;const length = parseInt(document.getElementById("length").value);const temperature = parseFloat(document.getElementById("temperature").value);const top_k = parseInt(document.getElementById("top_k").value);const data = {text: inputText,length: length,temperature: temperature,top_k: top_k};const response = await fetch('/generate', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(data)});const result = await response.json();document.getElementById("generatedText").innerText = result.generated_text;document.getElementById("reasoning").innerText = result.reasoning;document.getElementById("category").innerText = result.category;const outputDiv = document.getElementById("output");outputDiv.classList.add("show");applyFeedback(inputText, result.category)}async function applyFeedback(originalText, predictedCategory) {const correctCategory = prompt("Is category correct? Enter correct category or leave blank:");if (correctCategory) {const feedbackData = {text: originalText,category: correctCategory};await fetch('/generate', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(feedbackData)})}}</script></body></html>"""
35
 
36
  class GPT2Config:
37
- def __init__(self, vocab_size_or_config_json_file=50257, n_positions=1, n_ctx=1, n_embd=1, n_layer=1, n_head=1, layer_norm_epsilon=1e-5, initializer_range=0.02):
38
  self.vocab_size = vocab_size_or_config_json_file
39
  self.n_ctx = n_ctx
40
  self.n_positions = n_positions
 
34
  html_code = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI Text Generation Platform</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" /><style>body {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;background: linear-gradient(to right, #667eea, #764ba2);color: #fff;margin: 0;padding: 0;overflow: hidden;display: flex;justify-content: center;align-items: center;min-height: 100vh;}.container {width: 80%;max-width: 900px;margin: 50px auto;background: rgba(255, 255, 255, 0.1);padding: 40px;border-radius: 15px;box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.2);transition: transform 0.3s ease-in-out;}.container:hover {transform: translateY(-5px);}.header {text-align: center;margin-bottom: 40px;color: #fff;}.header h1 {font-size: 3.5em;font-weight: 600;letter-spacing: 1px;text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);}.header p {font-size: 1.2em;opacity: 0.8;text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);}.form-group {margin-bottom: 30px;}.form-group label {display: block;margin-bottom: 10px;font-size: 1.1em;font-weight: 500;opacity: 0.9;text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);}.form-group textarea, .form-group input[type="text"] {width: 100%;padding: 15px;border: none;border-radius: 8px;background: rgba(255, 255, 255, 0.2);color: #fff;font-size: 16px;box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);backdrop-filter: blur(8px);transition: all 0.3s ease;}.form-group textarea:focus, .form-group input[type="text"]:focus {outline: none;background: rgba(255, 255, 255, 0.3);box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.3);}button {width: 100%;padding: 15px;border: none;border-radius: 8px;background: linear-gradient(to right, #43cea2, #185a9d);color: #fff;font-size: 18px;font-weight: 500;cursor: pointer;box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);transition: background 0.3s ease;position: relative;overflow: hidden;}button:hover {background: linear-gradient(to left, #43cea2, #185a9d);}button::before {content: '\\f021';font-family: FontAwesome;position: absolute;top: 0;left: -30px;width: 30px;height: 100%;background: rgba(255, 255, 255, 0.3);display: flex;align-items: center;justify-content: center;transition: left 0.4s ease;}button:hover::before {left: 100%;transform: translateX(-100%);}.animated-text {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);font-size: 6em;font-weight: bold;color: rgba(255, 255, 255, 0.05);pointer-events: none;z-index: -1;}#output {margin-top: 40px;padding: 25px;border-radius: 10px;background: rgba(255, 255, 255, 0.1);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.2);white-space: pre-wrap;word-break: break-word;opacity: 0;transition: opacity 1s ease, transform 0.5s ease;transform: translateY(20px);}#output.show {opacity: 1;transform: translateY(0);}#output strong {color: #93b8c2;font-weight: 600;}@keyframes fadeIn {from {opacity: 0;transform: translateY(-20px);}to {opacity: 1;transform: translateY(0);}}</style></head><body><div class="animated-text animate__animated animate__fadeIn animate__infinite infinite">AI POWERED</div><div class="container"><div class="header animate__animated animate__fadeInDown"><h1>AI Text Generation Platform</h1><p>Unleash your creativity with our advanced text generation tool.</p></div><div class="form-group animate__animated animate__fadeInLeft"><label for="text">Input Text:</label><textarea id="text" rows="5" placeholder="Enter your text here"></textarea></div><div class="form-group animate__animated animate__fadeInRight"><label for="length">Length:</label><input type="text" id="length" value="50" placeholder="Enter desired length"></div><div class="form-group animate__animated animate__fadeInLeft"><label for="temperature">Temperature:</label><input type="text" id="temperature" value="0.7" placeholder="Enter temperature (0-1)"></div><div class="form-group animate__animated animate__fadeInRight"><label for="top_k">Top K:</label><input type="text" id="top_k" value="40" placeholder="Enter top K value"></div><button onclick="generateText()" class="animate__animated animate__fadeInUp">Generate Text</button><div id="output" class="animate__animated"><strong >Generated Text:</strong><br><span id="generatedText"></span><br><br><strong >Reasoning:</strong><br><span id="reasoning"></span><br><br><strong >Category:</strong><br><span id="category"></span></div></div><script>async function generateText() {const inputText = document.getElementById("text").value;const length = parseInt(document.getElementById("length").value);const temperature = parseFloat(document.getElementById("temperature").value);const top_k = parseInt(document.getElementById("top_k").value);const data = {text: inputText,length: length,temperature: temperature,top_k: top_k};const response = await fetch('/generate', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(data)});const result = await response.json();document.getElementById("generatedText").innerText = result.generated_text;document.getElementById("reasoning").innerText = result.reasoning;document.getElementById("category").innerText = result.category;const outputDiv = document.getElementById("output");outputDiv.classList.add("show");applyFeedback(inputText, result.category)}async function applyFeedback(originalText, predictedCategory) {const correctCategory = prompt("Is category correct? Enter correct category or leave blank:");if (correctCategory) {const feedbackData = {text: originalText,category: correctCategory};await fetch('/generate', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(feedbackData)})}}</script></body></html>"""
35
 
36
  class GPT2Config:
37
+ def __init__(self, vocab_size_or_config_json_file=50257, n_positions=8, n_ctx=8, n_embd=128, n_layer=1, n_head=1, layer_norm_epsilon=1e-5, initializer_range=0.02):
38
  self.vocab_size = vocab_size_or_config_json_file
39
  self.n_ctx = n_ctx
40
  self.n_positions = n_positions