Spaces:
Runtime error
Runtime error
Commit ·
7d906de
1
Parent(s): b45606e
main commit
Browse files- app.py +16 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from model import *
|
| 3 |
+
|
| 4 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 5 |
+
|
| 6 |
+
model = GPTLanguageModel().to(device)
|
| 7 |
+
model.load_state_dict(torch.load("mini-gpt.pth"))
|
| 8 |
+
|
| 9 |
+
answer = decode(model.generate(context, max_new_tokens=1000)[0].tolist())
|
| 10 |
+
|
| 11 |
+
def display(number):
|
| 12 |
+
return answer[:number+1]
|
| 13 |
+
|
| 14 |
+
input_slider = gr.inputs.Slider(minimum=500, maximum=1000, default=500, label="Select the maxium number of tokens/words:")
|
| 15 |
+
output_text = gr.outputs.Textbox()
|
| 16 |
+
gr.Interface(fn=display, inputs=input_slider, outputs=output_text).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
gradio
|