Nitzantry1 commited on
Commit
53a67f8
verified
1 Parent(s): 4da81f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -1,29 +1,23 @@
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)
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,
16
- do_sample=True,
17
- top_k=50,
18
- top_p=0.95,
19
- temperature=0.5, # 讛讜专讚转 讛讟诪驻专讟讜专讛 诇讛拽讟谞转 讛讗拽专讗讬讜转
20
- max_length=50, # 讛拽讟谞转 讛诪拽住讬诪讜诐 诇诪住驻专 拽讟谉 讬讜转专
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()
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client
2
  import gradio as gr
 
 
3
 
4
+ # 讞讬讘讜专 诇-Space 注诐 讛诪讜讚诇 讘-Hugging Face
5
+ client = Client("dicta-il/dictalm2.0-instruct-demo")
 
6
 
 
7
  def chat_with_model(prompt):
8
+ result = client.predict(
9
+ message=prompt,
10
+ api_name="/chat"
11
+ )
12
+ return result
 
 
 
 
 
 
 
 
 
13
 
14
+ # 讬爪讬专转 诪诪砖拽 诪转拽讚诐 注诐 Gradio
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("# Chat with DictaLM Model")
17
+ with gr.Row():
18
+ input_text = gr.Textbox(label="Enter your prompt here", lines=3)
19
+ output_text = gr.Textbox(label="Model's response", lines=5)
20
+ submit_btn = gr.Button("Submit")
21
+ submit_btn.click(chat_with_model, inputs=input_text, outputs=output_text)
22
+
23
+ demo.launch()