moxly commited on
Commit
e63d8d7
·
verified ·
1 Parent(s): 04f33bc

Create chatbot

Browse files
Files changed (1) hide show
  1. chatbot +25 -0
chatbot ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import gradio as gr
3
+
4
+ # Carregar o tokenizer e o modelo
5
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B")
6
+ model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-j-6B")
7
+
8
+ # Função para gerar resposta
9
+ def generate_response(prompt):
10
+ inputs = tokenizer(prompt, return_tensors="pt")
11
+ outputs = model.generate(inputs["input_ids"], max_length=150, num_return_sequences=1)
12
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return response
14
+
15
+ # Interface do Gradio
16
+ interface = gr.Interface(
17
+ fn=generate_response,
18
+ inputs=gr.Textbox(label="Pergunta"),
19
+ outputs=gr.Textbox(label="Resposta"),
20
+ title="Chatbot GPT-J",
21
+ description="Um chatbot simples usando GPT-J."
22
+ )
23
+
24
+ # Rodar a interface
25
+ interface.launch()