Arikkod commited on
Commit
c940093
โ€ข
1 Parent(s): 7232bde

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer, AutoModelForCausalLM
2
+ import gradio as gr
3
+ import torch
4
+
5
+
6
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
+ tokenizer = AutoTokenizer.from_pretrained("Norod78/hebrew-gpt_neo-xl", trust_remote_code=True)
8
+ model = AutoModelForCausalLM.from_pretrained("Norod78/hebrew-gpt_neo-xl", pad_token_id=tokenizer.eos_token_id)
9
+ model.to(device)
10
+
11
+
12
+ def predict(input, history=None):
13
+ if history is None:
14
+ history = []
15
+ response, history = model.chat(tokenizer, input, history)
16
+ return history, history
17
+
18
+
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown('''## ArikGPT - Trained on a dataset of chats, jokes and news in the Hebrew language''')
21
+ state = gr.State([])
22
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
23
+ with gr.Row():
24
+ with gr.Column(scale=4):
25
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
26
+ with gr.Column(scale=1):
27
+ button = gr.Button("Generate")
28
+ txt.submit(predict, [txt, state], [chatbot, state])
29
+ button.click(predict, [txt, state], [chatbot, state])
30
+
31
+ demo.queue().launch()
32
+
33
+ # Based on EleutherAI's gpt-neo 1.37B params