Spaces:
Running
on
Zero
Running
on
Zero
Update app.py (#20)
Browse files- Update app.py (b2fd83a77311896b1862d58e5e4f9c7ae84ef0f6)
- Update app.py (d79b96d6f3c7fecee1946ac29ceae6a35d872538)
Co-authored-by: Yanis Adel <[email protected]>
app.py
CHANGED
@@ -35,33 +35,40 @@ def read_dna_sequence(dna_text, fasta_file):
|
|
35 |
if dna_text and dna_text.strip():
|
36 |
dna_sequence = dna_text.strip().replace("\n", "")
|
37 |
|
38 |
-
#
|
39 |
if fasta_file is not None:
|
40 |
if dna_sequence:
|
41 |
-
warning = "Warning: Both pasted DNA and FASTA file provided. Using
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
|
62 |
if dna_sequence and not dna_sequence.isupper():
|
63 |
dna_sequence = dna_sequence.upper()
|
64 |
-
warning += "\
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
return dna_sequence, warning.strip(), error
|
67 |
|
@@ -85,18 +92,18 @@ def validate_inputs(dna_sequence: str, custom_question: str):
|
|
85 |
placeholders = custom_question.count("<DNA>")
|
86 |
|
87 |
if not custom_question.strip():
|
88 |
-
return False, "Please provide a question."
|
89 |
|
90 |
if dna_sequence and placeholders == 0:
|
91 |
log_message("Error: DNA sequence provided but no <DNA> token.")
|
92 |
-
return False, "Your question must contain the <DNA> token if you provide a DNA sequence."
|
93 |
|
94 |
if not dna_sequence and placeholders == 1:
|
95 |
log_message("Error: <DNA> token but no sequence.")
|
96 |
-
return False, "You must provide a DNA sequence if you use the <DNA> token."
|
97 |
|
98 |
if placeholders > 1:
|
99 |
-
return False, "Only one <DNA> token is allowed."
|
100 |
|
101 |
return True, ""
|
102 |
|
@@ -128,6 +135,8 @@ def run_chatnt(dna_text, fasta_file, custom_question):
|
|
128 |
if warning:
|
129 |
feedback_msgs.append(warning)
|
130 |
|
|
|
|
|
131 |
return result, "\n".join(feedback_msgs)
|
132 |
|
133 |
|
@@ -138,14 +147,14 @@ css = """
|
|
138 |
footer { display: none !important; }
|
139 |
"""
|
140 |
|
141 |
-
example_dna = "
|
142 |
-
example_question = "
|
143 |
|
144 |
with gr.Blocks(css=css) as demo:
|
145 |
gr.Markdown(
|
146 |
"""
|
147 |
# 🧬 ChatNT: A Multimodal Conversational Agent for DNA, RNA and Protein Tasks
|
148 |
-
[ChatNT](https://www.nature.com/articles/s42256-025-01047-1) is the first multimodal conversational agent designed with a deep understanding of biological sequences (DNA, RNA, proteins). It enables users — even those with no coding background — to interact with biological data through natural language and it generalizes across multiple biological tasks and modalities
|
149 |
|
150 |
This Hugging Face Space is powered by a [ZeroGPU](https://huggingface.co/docs/hub/en/spaces-zerogpu), which is free but **limited to 5 minutes per day per user**.
|
151 |
"""
|
@@ -205,20 +214,34 @@ You can either paste a sequence or upload a FASTA file.
|
|
205 |
|
206 |
---
|
207 |
|
208 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
- "Does this sequence `<DNA>` contain a donor splice site?"
|
210 |
- "Is it possible for you to identify whether there's a substantial presence of H3 histone protein occupancy in the nucleotide sequence `<DNA>` in yeast?"
|
211 |
- "Determine the degradation rate of the mouse RNA sequence `<DNA>` within the -5 to 5 range."
|
212 |
|
213 |
-
|
|
|
|
|
214 |
- "What is the length of this sequence `<DNA>`?"
|
215 |
-
- "Replace the all 'A' nucleotides by 'G' in this sequence `<DNA
|
216 |
|
217 |
For more examples, you can refer to the [training dataset](https://huggingface.co/datasets/InstaDeepAI/ChatNT_training_data).
|
218 |
"""
|
219 |
)
|
220 |
with gr.Column(scale=1):
|
221 |
-
gr.Image(
|
|
|
|
|
|
|
|
|
222 |
|
223 |
gr.Markdown("""
|
224 |
### 📚 Citation
|
|
|
35 |
if dna_text and dna_text.strip():
|
36 |
dna_sequence = dna_text.strip().replace("\n", "")
|
37 |
|
38 |
+
# Text overrides uploaded FASTA
|
39 |
if fasta_file is not None:
|
40 |
if dna_sequence:
|
41 |
+
warning = "⚠️ Warning: Both pasted DNA and FASTA file provided. Using the pasted DNA only."
|
42 |
|
43 |
+
else:
|
44 |
+
try:
|
45 |
+
with open(fasta_file.name, "r") as f:
|
46 |
+
content = f.read()
|
47 |
+
|
48 |
+
if not content.startswith(">"):
|
49 |
+
error = "❌ Invalid FASTA: must start with '>' header line."
|
50 |
+
return "", warning, error
|
51 |
+
|
52 |
+
sequence = ""
|
53 |
+
for line in content.splitlines():
|
54 |
+
if not line or line.startswith(">"):
|
55 |
+
continue
|
56 |
+
sequence += line.strip()
|
57 |
+
|
58 |
+
dna_sequence = sequence
|
59 |
+
|
60 |
+
except Exception:
|
61 |
+
error = "❌ Could not read the FASTA file."
|
62 |
|
63 |
if dna_sequence and not dna_sequence.isupper():
|
64 |
dna_sequence = dna_sequence.upper()
|
65 |
+
warning += "\n⚠️ Note: DNA sequence was converted to uppercase (lowercase nucleotides are not supported)."
|
66 |
+
|
67 |
+
if error != "":
|
68 |
+
# If there was an error before, no need to check the content of the sequence. Otherwise, check that only ACGTN are used
|
69 |
+
for nucleotide in dna_sequence:
|
70 |
+
if nucleotide not in ["A", "C", "G", "T", "N"]:
|
71 |
+
error = "❌ The nucleotides of the DNA sequence should be either 'A', 'T', 'G', 'C' or 'N'."
|
72 |
|
73 |
return dna_sequence, warning.strip(), error
|
74 |
|
|
|
92 |
placeholders = custom_question.count("<DNA>")
|
93 |
|
94 |
if not custom_question.strip():
|
95 |
+
return False, "❌ Please provide a question."
|
96 |
|
97 |
if dna_sequence and placeholders == 0:
|
98 |
log_message("Error: DNA sequence provided but no <DNA> token.")
|
99 |
+
return False, "❌ Your question must contain the <DNA> token if you provide a DNA sequence."
|
100 |
|
101 |
if not dna_sequence and placeholders == 1:
|
102 |
log_message("Error: <DNA> token but no sequence.")
|
103 |
+
return False, "❌ You must provide a DNA sequence if you use the <DNA> token."
|
104 |
|
105 |
if placeholders > 1:
|
106 |
+
return False, "❌ Only one <DNA> token is allowed."
|
107 |
|
108 |
return True, ""
|
109 |
|
|
|
135 |
if warning:
|
136 |
feedback_msgs.append(warning)
|
137 |
|
138 |
+
if len(feedback_msgs) == 0:
|
139 |
+
feedback_msgs.append("✅ Execution was succesful.")
|
140 |
return result, "\n".join(feedback_msgs)
|
141 |
|
142 |
|
|
|
147 |
footer { display: none !important; }
|
148 |
"""
|
149 |
|
150 |
+
example_dna = "AGGCGGTGGCAACAGCAACGATAGTTGCATCAGCGCTAACTGCTGCTGCTGCTGCGTGTTCTGCCGGAGGCTGCCGGGAGGGTACAGTAATGACTGTAGGGAGCGCACAGCCGCTGCGGCGGCAGGTTCCCTGGATCAGGAAATTAGGACAGGCACCCGGGATTGGAGGCGAGGGCGGCGCGCGAGCCAACCAGCGGTCGCCCCGGGCCCCCGTGAGCCCCAGGCGAACGCGCGGAGCAGCCGGGCCCCTAGAGCGGTCCGGGTGGCGGCGGCGGCAGCCACGACCACGACCGCGGTCAC"
|
151 |
+
example_question = "Is there a promoter element in human or mouse cells present in the nucleotide sequence <DNA>?"
|
152 |
|
153 |
with gr.Blocks(css=css) as demo:
|
154 |
gr.Markdown(
|
155 |
"""
|
156 |
# 🧬 ChatNT: A Multimodal Conversational Agent for DNA, RNA and Protein Tasks
|
157 |
+
[ChatNT](https://www.nature.com/articles/s42256-025-01047-1) is the first multimodal conversational agent designed with a deep understanding of biological sequences (DNA, RNA, proteins). It enables users — even those with no coding background — to interact with biological data through natural language and it generalizes across multiple biological tasks and modalities.
|
158 |
|
159 |
This Hugging Face Space is powered by a [ZeroGPU](https://huggingface.co/docs/hub/en/spaces-zerogpu), which is free but **limited to 5 minutes per day per user**.
|
160 |
"""
|
|
|
214 |
|
215 |
---
|
216 |
|
217 |
+
### Limitations and Disclaimer
|
218 |
+
ChatNT can only handle questions related to the 27 tasks it has been trained on, including the same format of DNA sequences. ChatNT is not a clinical or diagnostic tool. It can produce incorrect or “hallucinated” answers, particularly on out‑of‑distribution inputs, and its numeric predictions may suffer digit‑level errors. Confidence estimates require post‑hoc calibration. Users should always validate critical outputs against experiments or specialized bioinformatics pipelines.
|
219 |
+
|
220 |
+
### How to query the model ?
|
221 |
+
ChatNT works like an advanced assistant for analyzing DNA sequences — but it has some important rules.
|
222 |
+
|
223 |
+
#### ✅ What works well
|
224 |
+
ChatNT is good at answering biological questions about the meaning or function of the DNA sequence.
|
225 |
+
Examples of good queries:
|
226 |
- "Does this sequence `<DNA>` contain a donor splice site?"
|
227 |
- "Is it possible for you to identify whether there's a substantial presence of H3 histone protein occupancy in the nucleotide sequence `<DNA>` in yeast?"
|
228 |
- "Determine the degradation rate of the mouse RNA sequence `<DNA>` within the -5 to 5 range."
|
229 |
|
230 |
+
#### ❌ What does not work properly
|
231 |
+
ChatNT does not have direct access to the raw nucleotides of the DNA. Instead, it works with an internal representation of the sequence. This means it cannot answer questions about the exact nucleotides or modify the sequence for you.
|
232 |
+
Examples of bad queries:
|
233 |
- "What is the length of this sequence `<DNA>`?"
|
234 |
+
- "Replace the all 'A' nucleotides by 'G' in this sequence `<DNA>`".
|
235 |
|
236 |
For more examples, you can refer to the [training dataset](https://huggingface.co/datasets/InstaDeepAI/ChatNT_training_data).
|
237 |
"""
|
238 |
)
|
239 |
with gr.Column(scale=1):
|
240 |
+
gr.Image(
|
241 |
+
"https://media.springernature.com/w440/springer-static/cover-hires/journal/42256/7/6",
|
242 |
+
label=None,
|
243 |
+
show_label=False
|
244 |
+
)
|
245 |
|
246 |
gr.Markdown("""
|
247 |
### 📚 Citation
|