AmelieSchreiber commited on
Commit
00d2cb3
1 Parent(s): 1ee0fa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -65,22 +65,23 @@ 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, 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(
@@ -88,16 +89,11 @@ iface = gr.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
-
 
65
  plt.close()
66
  return temp_file
67
 
68
+ def heatmap_interface(sequence, start, end=None):
69
+ # Convert start and end to integers
70
+ start = int(start)
71
+ if end is not None:
72
+ end = int(end)
73
+
74
  # If end is None or greater than sequence length, set it to sequence length
75
+ if end is None or end > len(sequence) or end <= 0:
76
  end = len(sequence)
 
77
 
78
  # Ensure start is within bounds
79
+ if start < 1 or start > len(sequence):
80
  return "Start position is out of bounds."
81
 
82
  # Generate heatmap
83
  heatmap_path = generate_heatmap(sequence, start, end)
84
+ return heatmap_path
 
 
 
85
 
86
  # Define the Gradio interface
87
  iface = gr.Interface(
 
89
  inputs=[
90
  gr.Textbox(lines=2, placeholder="Enter Protein Sequence Here..."),
91
  gr.Number(label="Start Position", value=1),
92
+ gr.Number(label="End Position") # No default value needed
93
  ],
94
+ outputs="image",
 
 
 
 
95
  live=True
96
  )
97
 
98
  # Run the Gradio app
99
+ iface.launch()