Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,23 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
-
import torch
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
model = AutoModelForCausalLM.from_pretrained('dicta-il/dictalm-7b-instruct', trust_remote_code=True)
|
9 |
|
10 |
-
# 讛讙讚专转 讛驻讜谞拽爪讬讛 诇爪'讗讟 注诐 讛诪讜讚诇
|
11 |
def chat_with_model(prompt):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|