Spaces:
Sleeping
Sleeping
RandomNameAnd6
commited on
Commit
•
4ca3257
1
Parent(s):
c71254b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio transformers")
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import torch
|
6 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
7 |
+
|
8 |
+
tokenizer = GPT2Tokenizer.from_pretrained("RandomNameAnd6/DharGPT-Tokenizer")
|
9 |
+
model = GPT2LMHeadModel.from_pretrained("RandomNameAnd6/DharGPT").eval()
|
10 |
+
|
11 |
+
def generate_text(prompt):
|
12 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
13 |
+
output = model.generate(input_ids, max_length=512, temperature=0.9, do_sample=True)
|
14 |
+
text = tokenizer.decode(output[0], skip_special_tokens=True)
|
15 |
+
return text
|
16 |
+
|
17 |
+
demo = gr.Interface(fn=generate_text, inputs="text", outputs="text", live=True)
|
18 |
+
demo.launch()
|