NETKURD / app.py
Bsbhdjdoehe's picture
Update app.py
b56c814 verified
Raw History Blame Contribute Delete
1.18 kB
import os
import gradio as gr
from huggingface_hub import InferenceClient
# پەیوەندی بە مۆدێلەکەوە بە سادەترین شێوە
client = InferenceClient(model="meta-llama/Meta-Llama-3-8B-Instruct", token=os.environ.get("HF_TOKEN"))
def chat_fn(message, history):
# دروستکردنی مێژووی پەیامەکان بەو شێوازەی کە وەشانی 5.0.1 تێیدەگات
messages = [{"role": "system", "content": "تۆ ئەندازیارێکی زیرەکی کوردی بە ناوی نێتکورد."}]
for user_msg, ai_msg in history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": ai_msg})
messages.append({"role": "user", "content": message})
response = ""
for msg in client.chat_completion(messages=messages, max_tokens=1024, stream=True):
token = msg.choices[0].delta.content
if token:
response += token
yield response
# بەکارهێنانی ChatInterface کە جێگیرترین ڕێگەیە
demo = gr.ChatInterface(fn=chat_fn, title="🛠️ NetKurd AI")
if __name__ == "__main__":
demo.launch()