DharGPT-Demo / app.py
RandomNameAnd6's picture
Create app.py
4ca3257
raw
history blame
642 Bytes
import os
os.system("pip install gradio transformers")
import gradio as gr
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel
tokenizer = GPT2Tokenizer.from_pretrained("RandomNameAnd6/DharGPT-Tokenizer")
model = GPT2LMHeadModel.from_pretrained("RandomNameAnd6/DharGPT").eval()
def generate_text(prompt):
input_ids = tokenizer.encode(prompt, return_tensors="pt")
output = model.generate(input_ids, max_length=512, temperature=0.9, do_sample=True)
text = tokenizer.decode(output[0], skip_special_tokens=True)
return text
demo = gr.Interface(fn=generate_text, inputs="text", outputs="text", live=True)
demo.launch()