AmelieSchreiber commited on
Commit
1ee0fa8
·
1 Parent(s): ca3d0d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -65,26 +65,39 @@ def generate_heatmap(protein_sequence, start_pos=1, end_pos=None):
65
  plt.close()
66
  return temp_file
67
 
68
- def heatmap_interface(sequence, start, end):
69
- # Ensure start and end positions are within bounds
70
- if start < 1 or end > len(sequence):
71
- return "Start or end position is out of bounds."
 
 
 
 
 
72
 
73
  # Generate heatmap
74
  heatmap_path = generate_heatmap(sequence, start, end)
75
- return heatmap_path
 
 
 
76
 
77
  # Define the Gradio interface
78
  iface = gr.Interface(
79
  fn=heatmap_interface,
80
  inputs=[
81
- gr.Textbox(lines=2, placeholder="MAPLRKTYVLKLYVAGNTPNSVRALKTLNNILEKEFKGVYALKVIDVLKNPQLAEEDKILATPTLAKVLPPPVRRIIGDLSNREKVLIGLDLLYEEIGDQAEDDLGLE"),
82
- gr.Number(label="Start Position", value=1), # Use 'value' instead of 'default'
83
- gr.Number(label="End Position", value=len("MAPLRKTYVLKLYVAGNTPNSVRALKTLNNILEKEFKGVYALKVIDVLKNPQLAEEDKILATPTLAKVLPPPVRRIIGDLSNREKVLIGLDLLYEEIGDQAEDDLGLE")) # Example default end position
84
  ],
85
- outputs="image",
 
 
 
 
86
  live=True
87
  )
88
 
89
  # Run the Gradio app
90
  iface.launch()
 
 
65
  plt.close()
66
  return temp_file
67
 
68
+ def heatmap_interface(sequence, start, end, state):
69
+ # If end is None or greater than sequence length, set it to sequence length
70
+ if end is None or end > len(sequence):
71
+ end = len(sequence)
72
+ state['end'] = end # Update state
73
+
74
+ # Ensure start is within bounds
75
+ if start < 1:
76
+ return "Start position is out of bounds."
77
 
78
  # Generate heatmap
79
  heatmap_path = generate_heatmap(sequence, start, end)
80
+ return heatmap_path, state
81
+
82
+ # Initialize state with None for end position
83
+ initial_state = {'end': None}
84
 
85
  # Define the Gradio interface
86
  iface = gr.Interface(
87
  fn=heatmap_interface,
88
  inputs=[
89
+ gr.Textbox(lines=2, placeholder="Enter Protein Sequence Here..."),
90
+ gr.Number(label="Start Position", value=1),
91
+ gr.Number(label="End Position")
92
  ],
93
+ outputs=[
94
+ "image",
95
+ gr.State()
96
+ ],
97
+ state=initial_state,
98
  live=True
99
  )
100
 
101
  # Run the Gradio app
102
  iface.launch()
103
+