!pip install -q gradio openai import os import gradio as gr from openai import OpenAI # 🔑 SET YOUR GROQ API KEY HERE os.environ["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"] = "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" # 🤖 Create Groq client client =OpenAI( base_url="https://api.groq.com/openai/v1", api_key=os.environ.get("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") ) # 🧬 System prompt SYSTEM_PROMPT = """ You are a Bioinformatics AI assistant. You help with: - DNA, RNA, Protein analysis - FASTA format - BLAST explanation - Genetics and mutations Give simple, clear, scientific answers. """ # 🧠 memory storage history = [] # 🧬 GC Content function def gc_content(seq): seq = seq.upper() return round((seq.count("G")+seq.count("C"))/len(seq)*100, 2) if len(seq)>0 else 0 # 💬 Chat function def chat(message): global history # 🧬 Auto DNA detection seq = message.replace(" ", "").upper() if len(seq) > 10 and all(c in "ATGC" for c in seq): reply = f"""🧬 DNA Analysis: Length: {len(seq)} GC Content: {gc_content(seq)}% Sequence looks valid DNA. """ history.append((message, reply)) return history # 🤖 Build messages messages = [{"role": "system", "content": SYSTEM_PROMPT}] for u, b in history: messages.append({"role": "user", "content": u}) messages.append({"role": "assistant", "content": b}) messages.append({"role": "user", "content": message}) # 🔥 API call response = client.chat.completions.create( model="openai/gpt-oss-20b", messages=messages, temperature=0.7 ) reply = response.choices[0].message.content history.append((message, reply)) return history # 🎨 Gradio UI with gr.Blocks() as demo: gr.Markdown("# 🧬 Bioinformatics AI") chatbot = gr.Chatbot() msg = gr.Textbox(placeholder="Ask DNA, RNA, FASTA, BLAST or paste sequence...") btn = gr.Button("Send") clear = gr.Button("Clear Chat") def respond(m): return chat(m) msg.submit(respond, msg, chatbot) btn.click(respond, msg, chatbot) clear.click(lambda: [], None, chatbot) demo.launch() # 🔹 Install required libraries !pip install -q openai gradio # 🔹 Imports import os import gradio as gr from openai import OpenAI # 🔹 Set your Groq API Key os.environ["GROQ_API_KEY"] = "YOUR_GROQ_API_KEY_HERE" # 🔹 Groq client (OpenAI compatible) client = OpenAI( base_url="https://api.groq.com/openai/v1", api_key=os.environ["GROQ_API_KEY"] ) # 🔬 Bioinformatics system prompt SYSTEM_PROMPT = """ You are a professional Bioinformatics AI assistant. You help with DNA, RNA, protein analysis, BLAST, FASTA, gene functions, mutations, and sequencing. Explain clearly like ChatGPT in simple + expert format. """ # 🔹 Chat function def chat(user_input, history): messages = [{"role": "system", "content": SYSTEM_PROMPT}] for h in history: messages.append({"role": "user", "content": h[0]}) messages.append({"role": "assistant", "content": h[1]}) messages.append({"role": "user", "content": user_input}) response = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=messages ) return response.choices[0].message.content # 🔹 Gradio UI chatbot = gr.ChatInterface(fn=chat, title="🧬 Bioinformatics AI Chatbot (Groq)") chatbot.launch()