babilonczyk commited on
Commit
ece3e95
·
verified ·
1 Parent(s): 55227d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
 
1
  import gradio as gr
2
+ import zipfile
3
+ import sqlite3
4
+ import io
5
 
6
+ # Load DB from ZIP in memory
7
+ def get_connection_from_zip(zip_path: str, db_filename: str) -> sqlite3.Connection:
8
+ with zipfile.ZipFile(zip_path) as z:
9
+ with z.open(db_filename) as f:
10
+ db_bytes = io.BytesIO(f.read())
11
+ return sqlite3.connect(f"file:{db_filename}?mode=ro", uri=True, factory=sqlite3.Connection, database=db_bytes)
12
+
13
+ # Open connection once at startup
14
+ conn = get_connection_from_zip("proteins.db.zip", "proteins.db")
15
+ cursor = conn.cursor()
16
+
17
+ # Query function
18
+ def search_by_sequence(seq: str) -> str:
19
+ seq = seq.strip().upper()
20
+ cursor.execute("SELECT * FROM proteins WHERE sequence = ?", (seq,))
21
+ row = cursor.fetchone()
22
+
23
+ if not row:
24
+ return
25
+
26
+ col_names = [desc[0] for desc in cursor.description]
27
+ return "\n".join(f"{k}: {v}" for k, v in zip(col_names, row))
28
+
29
+ # Gradio UI
30
+ demo = gr.Interface(
31
+ fn=search_by_sequence,
32
+ inputs=gr.Textbox(label="Enter protein sequence"),
33
+ outputs=gr.Textbox(label="Protein metadata"),
34
+ title="SwissProt Search",
35
+ description="Search Swiss-Prot by full protein sequence (exact match)"
36
+ )
37
 
 
38
  demo.launch()