Nitzantry1 commited on
Commit
ef9cde4
verified
1 Parent(s): 1e382f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import torch
5
+
6
+ # 讟讜注谉 讗转 讛诪讜讚诇 讜讛-tokenizer
7
+ tokenizer = AutoTokenizer.from_pretrained('dicta-il/dictalm-7b-instruct')
8
+ model = AutoModelForCausalLM.from_pretrained('dicta-il/dictalm-7b-instruct', trust_remote_code=True).cuda()
9
+
10
+ # 讛讙讚专转 讛驻讜谞拽爪讬讛 诇爪'讗讟 注诐 讛诪讜讚诇
11
+ def chat_with_model(prompt):
12
+ model.eval()
13
+ with torch.inference_mode():
14
+ kwargs = dict(
15
+ inputs=tokenizer(prompt, return_tensors='pt').input_ids.to(model.device),
16
+ do_sample=True,
17
+ top_k=50,
18
+ top_p=0.95,
19
+ temperature=0.75,
20
+ max_length=100,
21
+ min_new_tokens=5
22
+ )
23
+ output = model.generate(**kwargs)
24
+ response_text = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
25
+ return response_text
26
+
27
+ # 讬爪讬专转 诪诪砖拽 注诐 Gradio
28
+ interface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="Chat with DictaLM Model")
29
+ interface.launch()