Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,6 +57,65 @@ with gr.Blocks() as demo:
|
|
| 57 |
msg.submit(lambda: "", None, msg)
|
| 58 |
|
| 59 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
|
|
|
|
| 57 |
msg.submit(lambda: "", None, msg)
|
| 58 |
|
| 59 |
demo.launch()
|
| 60 |
+
import gradio as gr
|
| 61 |
+
from groq import Groq
|
| 62 |
+
|
| 63 |
+
client = Groq(api_key="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")
|
| 64 |
+
|
| 65 |
+
SYSTEM_PROMPT = """
|
| 66 |
+
You are a professional Bioinformatics AI assistant like ChatGPT.
|
| 67 |
+
|
| 68 |
+
You can help with:
|
| 69 |
+
- DNA, RNA, protein sequences
|
| 70 |
+
- Gene mutation analysis
|
| 71 |
+
- FASTA format explanation
|
| 72 |
+
- BLAST search explanation
|
| 73 |
+
- Genetic diseases
|
| 74 |
+
- Molecular biology concepts
|
| 75 |
+
|
| 76 |
+
Always explain in simple and clear way with examples.
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
# 🧠 Chat function
|
| 80 |
+
def chat(message, history):
|
| 81 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 82 |
+
|
| 83 |
+
# memory (chat history)
|
| 84 |
+
for user, assistant in history:
|
| 85 |
+
messages.append({"role": "user", "content": user})
|
| 86 |
+
messages.append({"role": "assistant", "content": assistant})
|
| 87 |
+
|
| 88 |
+
messages.append({"role": "user", "content": message})
|
| 89 |
+
|
| 90 |
+
response = client.chat.completions.create(
|
| 91 |
+
model="llama-3.1-70b-versatile",
|
| 92 |
+
messages=messages,
|
| 93 |
+
temperature=0.7
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
reply = response.choices[0].message.content
|
| 97 |
+
|
| 98 |
+
history.append((message, reply))
|
| 99 |
+
return history, history
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# 🎨 UI (ChatGPT-like)
|
| 103 |
+
with gr.Blocks() as demo:
|
| 104 |
+
gr.Markdown("# 🧬 Bioinformatics ChatGPT AI")
|
| 105 |
+
gr.Markdown("Ask anything about DNA, RNA, proteins, genes, mutations etc.")
|
| 106 |
+
|
| 107 |
+
chatbot = gr.Chatbot()
|
| 108 |
+
state = gr.State([])
|
| 109 |
+
|
| 110 |
+
msg = gr.Textbox(placeholder="Ask your bioinformatics question...")
|
| 111 |
+
|
| 112 |
+
def respond(message, history):
|
| 113 |
+
return chat(message, history)
|
| 114 |
+
|
| 115 |
+
msg.submit(respond, [msg, state], [chatbot, state])
|
| 116 |
+
msg.submit(lambda: "", None, msg)
|
| 117 |
+
|
| 118 |
+
demo.launch()
|
| 119 |
|
| 120 |
|
| 121 |
|