Spaces:
Sleeping
Sleeping
File size: 3,560 Bytes
aee5456 | 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | {
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "f231fff1-3a4e-439d-adef-5da188d7ce58",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7860\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<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>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import gradio as gr\n",
"import joblib\n",
"import pandas as pd\n",
"\n",
"# Model ve scaler yükleniyor\n",
"model = joblib.load(\"xgb_model.pkl\")\n",
"scaler = joblib.load(\"scaler.pkl\")\n",
"\n",
"# Tahmin fonksiyonu\n",
"def predict_quality(pressure, temp_x_pressure, fusion_metric):\n",
" input_df = pd.DataFrame([[pressure, temp_x_pressure, fusion_metric]],\n",
" columns=[\"Pressure (kPa)\", \"Temperature x Pressure\", \"Material Fusion Metric\"])\n",
" scaled_data = scaler.transform(input_df)\n",
" prediction = model.predict(scaled_data)\n",
" return f\"🔍 Tahmin Edilen Kalite Skoru: {prediction[0]:.2f}\"\n",
"\n",
"# Chatbot formatında cevap veren fonksiyon\n",
"def respond(press, temp, fusion, chat_history):\n",
" result = predict_quality(press, temp, fusion)\n",
" chat_history.append({\"role\": \"user\", \"content\": \"Özellikleri girdim.\"})\n",
" chat_history.append({\"role\": \"assistant\", \"content\": result})\n",
" return chat_history\n",
"\n",
"# Arayüz\n",
"with gr.Blocks() as demo:\n",
" gr.Markdown(\"## 🛠️ Kalite Tahmini Chatbotu\")\n",
"\n",
" chatbot = gr.Chatbot(label=\"Kalite Tahmin Chatbotu\", type=\"messages\")\n",
" state = gr.State([])\n",
"\n",
" with gr.Row():\n",
" pressure = gr.Number(label=\"Pressure (kPa)\")\n",
" temp_x_pressure = gr.Number(label=\"Temperature x Pressure\")\n",
" fusion_metric = gr.Number(label=\"Material Fusion Metric\")\n",
"\n",
" send_btn = gr.Button(\"Tahmin Et\")\n",
"\n",
" send_btn.click(\n",
" fn=respond,\n",
" inputs=[pressure, temp_x_pressure, fusion_metric, state],\n",
" outputs=[chatbot],\n",
" queue=False\n",
" ).then(lambda chat: chat, inputs=[chatbot], outputs=[state])\n",
"\n",
"demo.launch()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b19e3507-2452-47b3-b404-72706e500516",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|