Spaces:
Sleeping
Sleeping
File size: 1,555 Bytes
912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 912e097 6b0aeb4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import gradio as gr
import os
from openai import OpenAI
# توکن از Secrets خوانده میشود - این خط درسته
client = OpenAI(
base_url="https://router.huggingface.co/v1",
api_key=os.environ.get("HF_TOKEN", "")
)
def chat_with_ai(message, history):
try:
completion = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V3.2-Exp:novita",
messages=[
{
"role": "system",
"content": "You are Ehteshami AI - a helpful Persian assistant. همیشه به فارسی پاسخ بده."
},
{
"role": "user",
"content": message
}
],
max_tokens=500
)
response = completion.choices[0].message.content
return response
except Exception as e:
return f"⚠️ خطا: {str(e)}"
# ساخت رابط چت
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🤖 Ehteshami AI")
gr.Markdown("**دستیار هوشمند فارسی شما**")
chatbot = gr.Chatbot(height=400)
msg = gr.Textbox(label="پیام شما", placeholder="سلام! چطوری میتونم کمک کنم؟")
def respond(message, chat_history):
bot_message = chat_with_ai(message, chat_history)
chat_history.append((message, bot_message))
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
demo.launch() |