Nitzantry1 commited on
Commit
53a67f8
โ€ข
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()