Spaces:
Runtime error
Runtime error
app update
Browse files
app.py
CHANGED
@@ -74,9 +74,7 @@ def generate(
|
|
74 |
eos_id:int = None,
|
75 |
) -> torch.Tensor:
|
76 |
"""Takes a conditioning sequence (prompt) as input and continues to generate as many tokens as requested.
|
77 |
-
|
78 |
The implementation of this function is modified from A. Karpathy's nanoGPT.
|
79 |
-
|
80 |
Args:
|
81 |
model: The model to use.
|
82 |
idx: Tensor of shape (T) with indices of the prompt sequence.
|
@@ -131,7 +129,7 @@ def generate(
|
|
131 |
|
132 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
133 |
|
134 |
-
def
|
135 |
encoded = tokenizer.encode(input_text, device=fabric.device)
|
136 |
max_returned_tokens = encoded.size(0) + max_tokens
|
137 |
|
@@ -148,4 +146,18 @@ def generate_dialogue(input_text, temperature=0.8, max_tokens=200, top_k=1):
|
|
148 |
|
149 |
return(tokenizer.decode(y))
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
|
|
|
74 |
eos_id:int = None,
|
75 |
) -> torch.Tensor:
|
76 |
"""Takes a conditioning sequence (prompt) as input and continues to generate as many tokens as requested.
|
|
|
77 |
The implementation of this function is modified from A. Karpathy's nanoGPT.
|
|
|
78 |
Args:
|
79 |
model: The model to use.
|
80 |
idx: Tensor of shape (T) with indices of the prompt sequence.
|
|
|
129 |
|
130 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
131 |
|
132 |
+
def generate_text(input_text, temperature=0.8, max_tokens=200, top_k=None):
|
133 |
encoded = tokenizer.encode(input_text, device=fabric.device)
|
134 |
max_returned_tokens = encoded.size(0) + max_tokens
|
135 |
|
|
|
146 |
|
147 |
return(tokenizer.decode(y))
|
148 |
|
149 |
+
import gradio as gr
|
150 |
+
|
151 |
+
title = "GPT from scratch"
|
152 |
+
|
153 |
+
description1 = "GPT implementation taken from <a href='https://github.com/Lightning-AI/lit-gpt'>Lit-GPT</a>. It is trained on a samples of the <a href='https://huggingface.co/datasets/togethercomputer/RedPajama-Data-1T-Sample'>RedPajama 1 trillion dataset</a> to understand how GPT's are trained and built. The github link can be found <a href='https://github.com/mkthoma/gpt_from_scratch'>here.</a>"
|
154 |
+
|
155 |
+
demo = gr.Interface(generate_text,
|
156 |
+
inputs=[gr.Textbox(label="Enter any prompt ", type="text", value="Once upon a time,"),
|
157 |
+
gr.Slider(minimum=0, maximum=1, step=0.1, value=0.8, label="Temperature"),
|
158 |
+
gr.Slider(minimum=200, maximum=1000, step=50, value=300, label="Max Tokens"),
|
159 |
+
gr.Slider(minimum=10, maximum=100, step=5, value=20, label="Top K")],
|
160 |
+
outputs=gr.Textbox(label="Text generated", type="text"), description=description1)
|
161 |
+
|
162 |
|
163 |
+
demo.launch()
|