Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,11 @@ client = OpenAI(
|
|
| 9 |
api_key=HF_TOKEN,
|
| 10 |
)
|
| 11 |
|
| 12 |
-
MODEL_ID = "
|
| 13 |
-
|
| 14 |
-
SYSTEM = "Sen MAIND AI'sin. Kısa ve net cevap ver."
|
| 15 |
|
| 16 |
def llm_reply(user_text: str) -> str:
|
| 17 |
-
|
| 18 |
model=MODEL_ID,
|
| 19 |
messages=[
|
| 20 |
{"role": "system", "content": SYSTEM},
|
|
@@ -23,7 +22,7 @@ def llm_reply(user_text: str) -> str:
|
|
| 23 |
temperature=0.7,
|
| 24 |
max_tokens=300,
|
| 25 |
)
|
| 26 |
-
return
|
| 27 |
|
| 28 |
def chat_fn(message, history):
|
| 29 |
history = history or []
|
|
@@ -32,18 +31,16 @@ def chat_fn(message, history):
|
|
| 32 |
try:
|
| 33 |
reply = llm_reply(message)
|
| 34 |
except Exception as e:
|
| 35 |
-
reply = f"
|
| 36 |
|
| 37 |
history.append({"role": "assistant", "content": reply})
|
| 38 |
return history
|
| 39 |
|
| 40 |
with gr.Blocks(title="MaindAI") as demo:
|
| 41 |
gr.Image("logo.png", height=120, show_label=False)
|
| 42 |
-
gr.Markdown("## 💙 MaindAI")
|
| 43 |
-
|
| 44 |
chatbot = gr.Chatbot(value=[])
|
| 45 |
msg = gr.Textbox(placeholder="Sor...", show_label=False)
|
| 46 |
-
|
| 47 |
msg.submit(chat_fn, [msg, chatbot], chatbot)
|
| 48 |
|
| 49 |
demo.launch()
|
|
|
|
| 9 |
api_key=HF_TOKEN,
|
| 10 |
)
|
| 11 |
|
| 12 |
+
MODEL_ID = "HuggingFaceTB/SmolLM3-3B:hf-inference"
|
| 13 |
+
SYSTEM = "Sen MAIND AI'sin. Kısa, net ve yardımcı cevap ver."
|
|
|
|
| 14 |
|
| 15 |
def llm_reply(user_text: str) -> str:
|
| 16 |
+
resp = client.chat.completions.create(
|
| 17 |
model=MODEL_ID,
|
| 18 |
messages=[
|
| 19 |
{"role": "system", "content": SYSTEM},
|
|
|
|
| 22 |
temperature=0.7,
|
| 23 |
max_tokens=300,
|
| 24 |
)
|
| 25 |
+
return (resp.choices[0].message.content or "").strip()
|
| 26 |
|
| 27 |
def chat_fn(message, history):
|
| 28 |
history = history or []
|
|
|
|
| 31 |
try:
|
| 32 |
reply = llm_reply(message)
|
| 33 |
except Exception as e:
|
| 34 |
+
reply = f"⚠️ Router hata: {e}"
|
| 35 |
|
| 36 |
history.append({"role": "assistant", "content": reply})
|
| 37 |
return history
|
| 38 |
|
| 39 |
with gr.Blocks(title="MaindAI") as demo:
|
| 40 |
gr.Image("logo.png", height=120, show_label=False)
|
| 41 |
+
gr.Markdown("## 💙 MaindAI — Chat")
|
|
|
|
| 42 |
chatbot = gr.Chatbot(value=[])
|
| 43 |
msg = gr.Textbox(placeholder="Sor...", show_label=False)
|
|
|
|
| 44 |
msg.submit(chat_fn, [msg, chatbot], chatbot)
|
| 45 |
|
| 46 |
demo.launch()
|