nono-chatbot / app.py
dinna1's picture
Update app.py
30caa71 verified
raw
history blame
904 Bytes
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()