Spaces:
Runtime error
Runtime error
File size: 3,950 Bytes
5062648 7669e0a 8aedac7 3058282 e405859 5d0f08d ea6ef25 d57f8d2 7669e0a ea6ef25 c52c0f1 1c571f3 c52c0f1 1c571f3 c52c0f1 1c571f3 c52c0f1 1c571f3 d57f8d2 c52c0f1 5d7013d c52c0f1 5dd830f 78148b4 c251a2e 78148b4 7669e0a 78148b4 7669e0a c52c0f1 58c694a c52c0f1 7669e0a c52c0f1 |
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
import gradio as gr
import torch
from torch import nn
import lightning.pytorch as pl
from torch.nn import functional as F
from utils import GPTLM,encode,decode
newmodel = GPTLM.load_from_checkpoint('shakespeare_gpt.pth')
def generate_dialogue(character_dropdown):
if character_dropdown == "NONE":
context = torch.zeros((1, 1), dtype=torch.long)
return decode(newmodel.model.generate(context, max_new_tokens=100)[0].tolist())
else:
context = torch.tensor([encode(character_dropdown)], dtype=torch.long)
output_dialogue = decode(newmodel.model.generate(context, max_new_tokens=100)[0].tolist())
# remove extra dialogue returned
output_dialogue = str(output_dialogue.split("\n\n")[0])
return output_dialogue
HTML_TEMPLATE = """
<style>
#app-header {
text-align: center;
background: rgba(255, 255, 255, 0.3); /* Semi-transparent white */
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
position: relative; /* To position the artifacts */
}
#app-header h1 {
color: #FF0000;
font-size: 2em;
margin-bottom: 10px;
}
.concept {
position: relative;
transition: transform 0.3s;
}
.concept:hover {
transform: scale(1.1);
}
.concept img {
width: 100px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.concept-description {
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
color: white;
padding: 5px 10px;
border-radius: 5px;
opacity: 0;
transition: opacity 0.3s;
}
.concept:hover .concept-description {
opacity: 1;
}
/* Artifacts */
</style>
<div id="app-header">
<!-- Artifacts -->
<div class="artifact large"></div>
<div class="artifact large"></div>
<div class="artifact large"></div>
<div class="artifact large"></div>
<!-- Content -->
<h1>SHAKESPEARE DIALOGUE GENERATOR</h1>
<p>Generate dialogue for Shakespearean character by selecting character from dropdown.</p>
<p>Model: GPT, Dataset: Tiny Shakespeare, Token limit: 100.</p>
"""
with gr.Blocks(theme=gr.themes.Glass(),css=".gradio-container {background: url('file=https://github.com/Delve-ERAV1/S20/assets/11761529/c0ff84a4-dde6-473e-a820-d3797040eb9d')}") as interface:
gr.HTML(value=HTML_TEMPLATE, show_label=False)
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
gr.Markdown("")
with gr.Row(scale=1):
character_dropdown = gr.Dropdown(
label="Select a Character",
choices=["NONE","ROMEO","JULIET","MENENIUS","ANTONIO"],
value='Dream'
)
outputs = gr.Textbox(
label="Generated Dialogue"
)
inputs = [character_dropdown]
with gr.Column(scale=1):
button = gr.Button("Generate")
button.click(generate_dialogue, inputs=inputs, outputs=outputs)
if __name__ == "__main__":
interface.launch(enable_queue=True) |