| | import gradio as gr |
| | import torch |
| | import torch.nn as nn |
| |
|
| | |
| | class SumModel(nn.Module): |
| | def __init__(self): |
| | super(SumModel, self).__init__() |
| | self.fc1 = nn.Linear(2, 128) |
| | self.fc2 = nn.Linear(128, 128) |
| | self.fc3 = nn.Linear(128, 1) |
| |
|
| | def forward(self, x): |
| | x = torch.relu(self.fc1(x)) |
| | x = torch.relu(self.fc2(x)) |
| | x = self.fc3(x) |
| | return x |
| |
|
| | |
| | model = SumModel() |
| | model.load_state_dict(torch.load('sum_model.pth')) |
| | model.eval() |
| |
|
| | |
| | def calculate_sum(num1, num2): |
| | |
| | inputs = torch.tensor([[num1, num2]]).float() |
| | |
| | |
| | with torch.no_grad(): |
| | outputs = model(inputs) |
| | |
| | |
| | predicted_sum = outputs.item() |
| | |
| | return predicted_sum |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=calculate_sum, |
| | inputs=["number", "number"], |
| | outputs="number", |
| | title="Sum Predictor", |
| | description="Enter two numbers to predict their sum" |
| | ) |
| |
|
| | |
| | iface.launch() |