ilaydabeyhan commited on
Commit
4fea3b3
·
verified ·
1 Parent(s): 4cc55e2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+
5
+ # Model ve scaler yükleniyor
6
+ model = joblib.load("xgb_model.pkl")
7
+ scaler = joblib.load("scaler.pkl")
8
+
9
+ # Tahmin fonksiyonu
10
+ def predict_quality(pressure, temp_x_pressure, fusion_metric):
11
+ input_df = pd.DataFrame([[pressure, temp_x_pressure, fusion_metric]],
12
+ columns=["Pressure (kPa)", "Temperature x Pressure", "Material Fusion Metric"])
13
+ scaled_data = scaler.transform(input_df)
14
+ prediction = model.predict(scaled_data)
15
+ return f"🔍 Tahmin Edilen Kalite Skoru: {prediction[0]:.2f}"
16
+
17
+ # Chatbot formatında cevap veren fonksiyon
18
+ def respond(press, temp, fusion, chat_history):
19
+ result = predict_quality(press, temp, fusion)
20
+ chat_history.append({"role": "user", "content": "Özellikleri girdim."})
21
+ chat_history.append({"role": "assistant", "content": result})
22
+ return chat_history
23
+
24
+ # Arayüz
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("## 🛠️ Kalite Tahmini Chatbotu")
27
+
28
+ chatbot = gr.Chatbot(label="Kalite Tahmin Chatbotu", type="messages")
29
+ state = gr.State([])
30
+
31
+ with gr.Row():
32
+ pressure = gr.Number(label="Pressure (kPa)")
33
+ temp_x_pressure = gr.Number(label="Temperature x Pressure")
34
+ fusion_metric = gr.Number(label="Material Fusion Metric")
35
+
36
+ send_btn = gr.Button("Tahmin Et")
37
+
38
+ send_btn.click(
39
+ fn=respond,
40
+ inputs=[pressure, temp_x_pressure, fusion_metric, state],
41
+ outputs=[chatbot],
42
+ queue=False
43
+ ).then(lambda chat: chat, inputs=[chatbot], outputs=[state])
44
+
45
+ demo.launch()