Spaces:
Sleeping
Sleeping
from gradio_client import Client | |
import gradio as gr | |
# ืืืืืจ ื-Space ืขื ืืืืื ื-Hugging Face | |
client = Client("dicta-il/dictalm2.0-instruct-demo") | |
def chat_with_model(history): | |
# ืงืืืช ืืืืืขื ืืืืจืื ื ืฉื ืฉืืื ืขื ืืื ืืืฉืชืืฉ | |
prompt = history[-1]["content"] | |
# ืฉืืืืช ืืืืืขื ืืืืื ืืงืืืช ืชืืืื | |
result = client.predict(message=prompt, api_name="/chat") | |
return history + [{"role": "user", "content": prompt}, {"role": "bot", "content": result}] | |
# ืืฆืืจืช ืืืฉืง ืืชืงืื ืขื Gradio ืืฆืืจืช ืฆ'ื-ืืื ืืกืื ืื ืืงืืื | |
with gr.Blocks(theme="default") as demo: | |
gr.HTML(""" | |
<div style="background-color: #f5f5f5; padding: 20px; text-align: center;"> | |
<h1 style="color: #003366; font-family: Arial, sans-serif;">ืฆ'ืื ืขื ืืืื DictaLM</h1> | |
<p style="font-family: Arial, sans-serif; color: #333;">ืืจืืืื ืืืืื ืืฆ'ืื ืืืื ืืจืืงืืืื ืฉืื ื, ืืืืคืฉืจ ืืื ืืืชื ืกืืช ืืฉืืื ืขื ืืืื AI ืืชืงืื.</p> | |
</div> | |
""") | |
chatbot = gr.Chatbot(label="ืฆ'ืื ืขื ืืืื DictaLM", type="messages") | |
with gr.Row(): | |
user_input = gr.Textbox(placeholder="ืืื ืก ืืช ืืืืืขื ืฉืื ืืื...", label="", lines=1) | |
send_button = gr.Button("ืฉืื") | |
def user_chat(history, message): | |
# ืืืกืคืช ืืืืขืช ืืืฉืชืืฉ ืืืืกืืืจืื ืืคื ื ืฉืืืืช ืืฉืืื ืืืืื | |
return history + [{"role": "user", "content": message}], "" | |
# ืฉืืืืช ืืืืืขื ืื ืืืืืฆื ืขื Enter ืืื ืขื ืืื ืืืืฆื ืขื ืืคืชืืจ "ืฉืื" | |
user_input.submit(fn=user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False).then( | |
fn=chat_with_model, inputs=chatbot, outputs=chatbot | |
) | |
send_button.click(fn=user_chat, inputs=[chatbot, user_input], outputs=[chatbot, user_input], queue=False).then( | |
fn=chat_with_model, inputs=chatbot, outputs=chatbot | |
) | |
demo.launch() | |