Zerx966 commited on
Commit
87c1d92
1 Parent(s): e5e92d3

Create App

Browse files
Files changed (1) hide show
  1. App +33 -0
App ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from mamba_model import MambaModel
4
+
5
+ # Load the model
6
+ model = MambaModel.from_pretrained(pretrained_model_name="Zyphra/BlackMamba-2.8B")
7
+ model = model.cuda().half()
8
+
9
+ # Define the function to generate output
10
+ def generate_output(input_text):
11
+ # Convert the input text (comma-separated numbers) to a list of integers
12
+ try:
13
+ input_ids = [int(x.strip()) for x in input_text.split(",")]
14
+ inputs = torch.tensor(input_ids).cuda().long().unsqueeze(0)
15
+
16
+ # Run the model and get output
17
+ with torch.no_grad():
18
+ out = model(inputs)
19
+
20
+ # Convert output to a human-readable format
21
+ return out.cpu().numpy().tolist()
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ # Set up the Gradio interface
26
+ input_component = gr.Textbox(label="Input IDs (comma-separated)", placeholder="Enter input IDs like: 1, 2")
27
+ output_component = gr.Textbox(label="Output")
28
+
29
+ iface = gr.Interface(fn=generate_output, inputs=input_component, outputs=output_component, title="BlackMamba Model")
30
+
31
+ # Launch the interface
32
+ if __name__ == "__main__":
33
+ iface.launch()