Spaces:
Sleeping
Sleeping
Upload app.py
Browse filesadded application file app.py
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import data_utils
|
5 |
+
from gpt_language_model import GPTLanguageModel
|
6 |
+
|
7 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
8 |
+
|
9 |
+
inference_model = GPTLanguageModel()
|
10 |
+
|
11 |
+
inference_model.load_state_dict(torch.load('model/friendsGPT.pth', map_location=torch.device('cpu')))
|
12 |
+
inferenceModel = inference_model.to(device)
|
13 |
+
|
14 |
+
def generate():
|
15 |
+
context = torch.zeros((1, 1), dtype=torch.long, device=device)
|
16 |
+
print("Context prepared")
|
17 |
+
output = data_utils.decode(inferenceModel.generate(context, max_new_tokens=500)[0].tolist())
|
18 |
+
print("Output : ", output)
|
19 |
+
return output
|
20 |
+
|
21 |
+
|
22 |
+
demo = gr.Interface(fn=generate, inputs=None, outputs="text", title="F.R.I.E.N.D.S GPT", thumbnail="FRIENDS.jpg")
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
demo.launch(share=True)
|