File size: 2,113 Bytes
0a7f3eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
# বাংলা মন্তব্য সহ Hugging Face Space deploy-ready কোড

import gradio as gr
import torch
import torch.nn as nn

# -----------------------------
# Hybrid Model Design
# -----------------------------
class HybridModel(nn.Module):
    def __init__(self, input_size=1, hidden_size=64, num_layers=2):
        super(HybridModel, self).__init__()
        # LSTM sequence শেখার জন্য
        self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)
        # Transformer context শেখার জন্য
        encoder_layer = nn.TransformerEncoderLayer(d_model=hidden_size, nhead=4)
        self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=2)
        # Output layer
        self.fc = nn.Linear(hidden_size, 1)

    def forward(self, x):
        lstm_out, _ = self.lstm(x)
        trans_out = self.transformer(lstm_out)
        out = self.fc(trans_out[:, -1, :])
        return out

# Dummy model (শুধু demo এর জন্য)
model = HybridModel()

# -----------------------------
# Prediction Function
# -----------------------------
def predict(input_value):
    try:
        val = float(input_value)
        x = torch.tensor([[[val]]], dtype=torch.float32)
        with torch.no_grad():
            pred = model(x).item()
        return f"🔮 Prediction: {pred:.2f}"
    except:
        return "❌ Invalid input! Please enter a number like 2.1"

# -----------------------------
# Gradio UI
# -----------------------------
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
    gr.Markdown("## 🟣 Real-Time Hybrid AI Prediction System\nবাংলায় সহজ UI, Dark Mode")

    with gr.Row():
        input_box = gr.Textbox(label="Live Data Input (e.g. 2.1)", placeholder="Type number ➕ ⬜ ➖ ▫️ ➕ ⬜ ➖")
    output_box = gr.Textbox(label="Prediction Result", interactive=False)

    input_box.change(fn=predict, inputs=input_box, outputs=output_box)

    # CSV Upload Option
    csv_file = gr.File(label="Upload CSV for Initial Learning", file_types=[".csv"])

demo.launch()