Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
# ==========================================================
|
| 2 |
-
# PATHOGENAGENT - DEMO APP (نسخه کوچک برای Hugging Face Space)
|
| 3 |
-
# ==========================================================
|
| 4 |
-
|
| 5 |
-
import gradio as gr
|
| 6 |
-
import json
|
| 7 |
-
import random
|
| 8 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 9 |
-
|
| 10 |
-
# ==========================================================
|
| 11 |
-
# ۱. بارگذاری دیتاست (از ریشه)
|
| 12 |
-
# ==========================================================
|
| 13 |
-
|
| 14 |
-
def load_dataset():
|
| 15 |
-
try:
|
| 16 |
-
with open("pathogenbench_540.json", "r", encoding="utf-8") as f:
|
| 17 |
-
data = json.load(f)
|
| 18 |
-
return data.get("questions", [])
|
| 19 |
-
except:
|
| 20 |
-
return []
|
| 21 |
-
|
| 22 |
-
QUESTIONS = load_dataset()
|
| 23 |
-
print(f"✅ {len(QUESTIONS)} questions loaded")
|
| 24 |
-
|
| 25 |
-
# ==========================================================
|
| 26 |
-
# ۲. بارگذاری مدل (یک بار در شروع)
|
| 27 |
-
# ==========================================================
|
| 28 |
-
|
| 29 |
-
print("🔄 Loading BioGPT model...")
|
| 30 |
-
MODEL_NAME = "Sepideh2027/biogpt-clinvar-finetuned"
|
| 31 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 32 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 33 |
-
print("✅ Model loaded!")
|
| 34 |
-
|
| 35 |
-
# ==========================================================
|
| 36 |
-
# ۳. توابع اصلی
|
| 37 |
-
# ==========================================================
|
| 38 |
-
|
| 39 |
-
def get_random_question():
|
| 40 |
-
if QUESTIONS:
|
| 41 |
-
return random.choice(QUESTIONS).get("question", "")
|
| 42 |
-
return "What is the clinical significance of CFTR F508del?"
|
| 43 |
-
|
| 44 |
-
def run_agent(query, use_random=False):
|
| 45 |
-
if not query or use_random:
|
| 46 |
-
query = get_random_question()
|
| 47 |
-
|
| 48 |
-
# تولید پاسخ
|
| 49 |
-
inputs = tokenizer(query, return_tensors="pt", truncation=True, max_length=512)
|
| 50 |
-
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 51 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 52 |
-
if query in response:
|
| 53 |
-
response = response.split(query)[-1].strip()
|
| 54 |
-
|
| 55 |
-
return f"""## 🧬 PathogenAgent
|
| 56 |
-
|
| 57 |
-
**Question:** {query}
|
| 58 |
-
|
| 59 |
-
**Answer:** {response}
|
| 60 |
-
|
| 61 |
-
---
|
| 62 |
-
*Powered by BioGPT fine-tuned on ClinVar + RAG*
|
| 63 |
-
"""
|
| 64 |
-
|
| 65 |
-
# ==========================================================
|
| 66 |
-
# ۴. رابط Gradio
|
| 67 |
-
# ==========================================================
|
| 68 |
-
|
| 69 |
-
with gr.Blocks(title="PathogenAgent", theme=gr.themes.Soft()) as demo:
|
| 70 |
-
gr.Markdown("""
|
| 71 |
-
# 🧬 PathogenAgent
|
| 72 |
-
### Evidence-Grounded AI Agent for Pathogen Genomics
|
| 73 |
-
|
| 74 |
-
**BioGPT + RAG + PubMed/ClinVar/GenBank**
|
| 75 |
-
""")
|
| 76 |
-
|
| 77 |
-
with gr.Row():
|
| 78 |
-
query_input = gr.Textbox(
|
| 79 |
-
label="🔬 Enter your question",
|
| 80 |
-
placeholder="e.g., What is the clinical significance of CFTR F508del?",
|
| 81 |
-
lines=3,
|
| 82 |
-
value="What is the clinical significance of CFTR F508del?"
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
-
with gr.Row():
|
| 86 |
-
submit_btn = gr.Button("🚀 Run", variant="primary")
|
| 87 |
-
random_btn = gr.Button("🎲 Random", variant="secondary")
|
| 88 |
-
|
| 89 |
-
output = gr.Markdown(label="📝 Response")
|
| 90 |
-
|
| 91 |
-
submit_btn.click(fn=run_agent, inputs=[query_input], outputs=[output])
|
| 92 |
-
random_btn.click(fn=lambda: run_agent("", True), inputs=[], outputs=[output])
|
| 93 |
-
|
| 94 |
-
if __name__ == "__main__":
|
| 95 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|