Spaces:
Sleeping
Sleeping
Upload tahmin_modeli.py
Browse files- tahmin_modeli.py +116 -0
tahmin_modeli.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 3,
|
| 6 |
+
"id": "f231fff1-3a4e-439d-adef-5da188d7ce58",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stdout",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
| 14 |
+
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"data": {
|
| 19 |
+
"text/html": [
|
| 20 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 21 |
+
],
|
| 22 |
+
"text/plain": [
|
| 23 |
+
"<IPython.core.display.HTML object>"
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"output_type": "display_data"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"data": {
|
| 31 |
+
"text/plain": []
|
| 32 |
+
},
|
| 33 |
+
"execution_count": 3,
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"output_type": "execute_result"
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"source": [
|
| 39 |
+
"import gradio as gr\n",
|
| 40 |
+
"import joblib\n",
|
| 41 |
+
"import pandas as pd\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"# Model ve scaler yükleniyor\n",
|
| 44 |
+
"model = joblib.load(\"xgb_model.pkl\")\n",
|
| 45 |
+
"scaler = joblib.load(\"scaler.pkl\")\n",
|
| 46 |
+
"\n",
|
| 47 |
+
"# Tahmin fonksiyonu\n",
|
| 48 |
+
"def predict_quality(pressure, temp_x_pressure, fusion_metric):\n",
|
| 49 |
+
" input_df = pd.DataFrame([[pressure, temp_x_pressure, fusion_metric]],\n",
|
| 50 |
+
" columns=[\"Pressure (kPa)\", \"Temperature x Pressure\", \"Material Fusion Metric\"])\n",
|
| 51 |
+
" scaled_data = scaler.transform(input_df)\n",
|
| 52 |
+
" prediction = model.predict(scaled_data)\n",
|
| 53 |
+
" return f\"🔍 Tahmin Edilen Kalite Skoru: {prediction[0]:.2f}\"\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"# Chatbot formatında cevap veren fonksiyon\n",
|
| 56 |
+
"def respond(press, temp, fusion, chat_history):\n",
|
| 57 |
+
" result = predict_quality(press, temp, fusion)\n",
|
| 58 |
+
" chat_history.append({\"role\": \"user\", \"content\": \"Özellikleri girdim.\"})\n",
|
| 59 |
+
" chat_history.append({\"role\": \"assistant\", \"content\": result})\n",
|
| 60 |
+
" return chat_history\n",
|
| 61 |
+
"\n",
|
| 62 |
+
"# Arayüz\n",
|
| 63 |
+
"with gr.Blocks() as demo:\n",
|
| 64 |
+
" gr.Markdown(\"## 🛠️ Kalite Tahmini Chatbotu\")\n",
|
| 65 |
+
"\n",
|
| 66 |
+
" chatbot = gr.Chatbot(label=\"Kalite Tahmin Chatbotu\", type=\"messages\")\n",
|
| 67 |
+
" state = gr.State([])\n",
|
| 68 |
+
"\n",
|
| 69 |
+
" with gr.Row():\n",
|
| 70 |
+
" pressure = gr.Number(label=\"Pressure (kPa)\")\n",
|
| 71 |
+
" temp_x_pressure = gr.Number(label=\"Temperature x Pressure\")\n",
|
| 72 |
+
" fusion_metric = gr.Number(label=\"Material Fusion Metric\")\n",
|
| 73 |
+
"\n",
|
| 74 |
+
" send_btn = gr.Button(\"Tahmin Et\")\n",
|
| 75 |
+
"\n",
|
| 76 |
+
" send_btn.click(\n",
|
| 77 |
+
" fn=respond,\n",
|
| 78 |
+
" inputs=[pressure, temp_x_pressure, fusion_metric, state],\n",
|
| 79 |
+
" outputs=[chatbot],\n",
|
| 80 |
+
" queue=False\n",
|
| 81 |
+
" ).then(lambda chat: chat, inputs=[chatbot], outputs=[state])\n",
|
| 82 |
+
"\n",
|
| 83 |
+
"demo.launch()\n"
|
| 84 |
+
]
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"cell_type": "code",
|
| 88 |
+
"execution_count": null,
|
| 89 |
+
"id": "b19e3507-2452-47b3-b404-72706e500516",
|
| 90 |
+
"metadata": {},
|
| 91 |
+
"outputs": [],
|
| 92 |
+
"source": []
|
| 93 |
+
}
|
| 94 |
+
],
|
| 95 |
+
"metadata": {
|
| 96 |
+
"kernelspec": {
|
| 97 |
+
"display_name": "Python [conda env:base] *",
|
| 98 |
+
"language": "python",
|
| 99 |
+
"name": "conda-base-py"
|
| 100 |
+
},
|
| 101 |
+
"language_info": {
|
| 102 |
+
"codemirror_mode": {
|
| 103 |
+
"name": "ipython",
|
| 104 |
+
"version": 3
|
| 105 |
+
},
|
| 106 |
+
"file_extension": ".py",
|
| 107 |
+
"mimetype": "text/x-python",
|
| 108 |
+
"name": "python",
|
| 109 |
+
"nbconvert_exporter": "python",
|
| 110 |
+
"pygments_lexer": "ipython3",
|
| 111 |
+
"version": "3.12.7"
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
+
"nbformat": 4,
|
| 115 |
+
"nbformat_minor": 5
|
| 116 |
+
}
|