File size: 904 Bytes
47e6e94
30caa71
79b8b80
30caa71
 
b5ac77b
5038547
30caa71
 
 
 
47e6e94
79b8b80
 
b5ac77b
79b8b80
30caa71
 
79b8b80
d743ebd
79b8b80
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# โœ… ุชุญู…ูŠู„ ู…ูˆุฏูŠู„ ู…ุฌุงู†ูŠ ู…ู† Hugging Face
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct", device=0 if hasattr(__import__('torch'), 'cuda') and __import__('torch').cuda.is_available() else -1)

def respond(message):
    prompt = f"[INST] {message} [/INST]"
    result = chatbot(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
    reply = result[0]["generated_text"].replace(prompt, "").strip()
    return reply

iface = gr.Interface(
    fn=respond,
    inputs=gr.Textbox(lines=1, placeholder="ุงุณุฃู„ ู†ูˆู†ูˆ ุฃูŠ ุณุคุงู„!"),
    outputs=gr.Textbox(label="ุฑุฏ ู†ูˆู†ูˆ"),
    title="ู†ูˆู†ูˆ ุดุงุช ุจูˆุช (ู†ุณุฎุฉ ู…ุฌุงู†ูŠุฉ)",
    description="ู†ูˆู†ูˆ ุจูŠุฑุฏ ุนู„ูŠูƒ ุจุงุณุชุฎุฏุงู… ู…ูˆุฏูŠู„ ู…ุฌุงู†ูŠ ู…ู† Hugging Face ๐Ÿ˜Š"
)

if __name__ == "__main__":
    iface.launch()