File size: 839 Bytes
caa0347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import gradio as gr

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained("gpt2")


def generate_response(input_text):
    input_ids = tokenizer.encode(input_text, return_tensors='pt')
    generated_output = model.generate(input_ids, max_length=100, num_return_sequences=1)
    response = tokenizer.decode(generated_output[0], skip_special_tokens=True)
    return response


iface = gr.Interface(
    fn=generate_response,
    inputs='text',
    outputs='text',
    layout='vertical',
    title='ChatGPT',
    description='A simple chatbot powered by ChatGPT',
    article= 'https://huggingface.co/models',
    examples=[['Hello'], ['How are you?'], ['What is your name?']],
)

iface.launch()