Update app.py
Browse files
app.py
CHANGED
@@ -335,6 +335,141 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="slate", n
|
|
335 |
document.head.appendChild(style);
|
336 |
}
|
337 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
|
339 |
|
340 |
# Launch the interface
|
|
|
335 |
document.head.appendChild(style);
|
336 |
}
|
337 |
""")
|
338 |
+
|
339 |
+
# Add CSS styling
|
340 |
+
with gr.Blocks() as demo: # Use blocks to add javascript styling
|
341 |
+
gr.Markdown("# Chat with Gemini 2.0 Flash and See its Thoughts π")
|
342 |
+
|
343 |
+
gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Faiqcamp-Gemini2-Flash-Thinking.hf.space">
|
344 |
+
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Faiqcamp-Gemini2-Flash-Thinking.hf.space&countColor=%23263759" />
|
345 |
+
</a>""")
|
346 |
+
|
347 |
+
with gr.Tabs():
|
348 |
+
with gr.TabItem("Chat"):
|
349 |
+
chatbot = gr.Chatbot(
|
350 |
+
type="messages",
|
351 |
+
label="Gemini2.0 'Thinking' Chatbot (Streaming Output)", #Label now indicates streaming
|
352 |
+
render_markdown=True,
|
353 |
+
scale=1,
|
354 |
+
avatar_images=(None,"https://lh3.googleusercontent.com/oxz0sUBF0iYoN4VvhqWTmux-cxfD1rxuYkuFEfm1SFaseXEsjjE4Je_C_V3UQPuJ87sImQK3HfQ3RXiaRnQetjaZbjJJUkiPL5jFJ1WRl5FKJZYibUA=w214-h214-n-nu"),
|
355 |
+
elem_classes="chatbot-wrapper" # Add a class for custom styling
|
356 |
+
)
|
357 |
+
|
358 |
+
with gr.Row(equal_height=True):
|
359 |
+
input_box = gr.Textbox(
|
360 |
+
lines=1,
|
361 |
+
label="Chat Message",
|
362 |
+
placeholder="Type your message here...",
|
363 |
+
scale=4
|
364 |
+
)
|
365 |
+
|
366 |
+
clear_button = gr.Button("Clear Chat", scale=1)
|
367 |
+
|
368 |
+
# Add example prompts - removed file upload examples. Kept text focused examples.
|
369 |
+
example_prompts = [
|
370 |
+
["Explain the interplay between CYP450 enzymes and drug metabolism, specifically focusing on how enzyme induction or inhibition might affect the therapeutic efficacy of a drug such as warfarin."],
|
371 |
+
["λ§μ± μ μ₯ μ§ν νμμμ λΉν μΉλ£λ₯Ό μν΄ μ¬μ©νλ μ리μ€λ‘ν¬μ΄μν΄ μ μ μ μ½λνμ λ° μ½λ ₯νμ νΉμ±μ μμΈν λΆμνκ³ , ν¬μ¬ μ©λ λ° ν¬μ¬ κ°κ²© κ²°μ μ μν₯μ λ―ΈμΉλ μμΈλ€μ μ€λͺ
ν΄ μ£Όμμμ€.",""],
|
372 |
+
["κ°κ²½λ³ νμμμ μ½λ¬Ό λμ¬μ λ³νλ₯Ό μ€λͺ
νκ³ , κ° κΈ°λ₯ μ νκ° μ½λ¬Ό ν¬μ¬λ μ‘°μ μ λ―ΈμΉλ μν₯μ ꡬ체μ μΈ μ½λ¬Ό μμμ ν¨κ» λ
Όμν΄ μ£Όμμμ€. νΉν, κ° λμ¬ ν¨μμ νμ± λ³νμ κ·Έ μμμ μ€μμ±μ μ€λͺ
ν΄ μ£Όμμμ€."],
|
373 |
+
["μμΈ νμ΄λ¨Έλ³ μΉλ£μ ν¨κ³Όμ μΈ μ²μ° μλ¬Ό λ¬Όμ§κ³Ό μ½λ¦¬κΈ°μ λ±μ νλ°©(νμν)μ κ΄μ μμ μ€λͺ
νκ³ μλ €μ€"],
|
374 |
+
["κ³ νμ μΉλ£ λ° μ¦μ μνμ ν¨κ³Όμ μΈ μ μ½ κ°λ°μ μν΄ κ°λ₯μ±μ΄ λ§€μ° λμ μ²μ° μλ¬Ό λ¬Όμ§κ³Ό μ½λ¦¬κΈ°μ λ±μ νλ°©(νμν)μ κ΄μ μμ μ€λͺ
νκ³ μλ €μ€"],
|
375 |
+
["Compare and contrast the mechanisms of action of ACE inhibitors and ARBs in managing hypertension, considering their effects on the renin-angiotensin-aldosterone system."],
|
376 |
+
["Describe the pathophysiology of type 2 diabetes and explain how metformin achieves its glucose-lowering effects, including any key considerations for patients with renal impairment."],
|
377 |
+
["Please discuss the mechanism of action and clinical significance of beta-blockers in the treatment of heart failure, with reference to specific beta-receptor subtypes and their effects on the cardiovascular system."],
|
378 |
+
["μμΈ νμ΄λ¨Έλ³μ λ³νμ리νμ κΈ°μ μ μ€λͺ
νκ³ , νμ¬ μ¬μ©λλ μ½λ¬Όλ€μ΄ μμ©νλ μ£Όμ νκ²μ μμΈν κΈ°μ νμμμ€. νΉν, μμΈνΈμ½λ¦°μμ€ν
λΌμ μ΅μ μ μ NMDA μμ©μ²΄ κΈΈνμ μ μμ© λ°©μκ³Ό μμμ μμλ₯Ό λΉκ΅ λΆμν΄ μ£Όμμμ€."]
|
379 |
+
|
380 |
+
]
|
381 |
+
|
382 |
+
gr.Examples(
|
383 |
+
examples=example_prompts,
|
384 |
+
inputs=input_box,
|
385 |
+
label="Examples: Try these prompts to see Gemini's thinking!",
|
386 |
+
examples_per_page=3 # Adjust as needed
|
387 |
+
)
|
388 |
+
|
389 |
+
|
390 |
+
# Set up event handlers
|
391 |
+
msg_store = gr.State("") # Store for preserving user message
|
392 |
+
|
393 |
+
input_box.submit(
|
394 |
+
lambda msg: (msg, msg, ""), # Store message and clear input
|
395 |
+
inputs=[input_box],
|
396 |
+
outputs=[msg_store, input_box, input_box],
|
397 |
+
queue=False
|
398 |
+
).then(
|
399 |
+
user_message, # Add user message to chat
|
400 |
+
inputs=[msg_store, chatbot],
|
401 |
+
outputs=[input_box, chatbot],
|
402 |
+
queue=False
|
403 |
+
).then(
|
404 |
+
stream_gemini_response, # Generate and stream response
|
405 |
+
inputs=[msg_store, chatbot],
|
406 |
+
outputs=chatbot
|
407 |
+
)
|
408 |
+
|
409 |
+
clear_button.click(
|
410 |
+
lambda: ([], "", ""),
|
411 |
+
outputs=[chatbot, input_box, msg_store],
|
412 |
+
queue=False
|
413 |
+
)
|
414 |
+
|
415 |
+
with gr.TabItem("Instructions"):
|
416 |
+
gr.Markdown(
|
417 |
+
"""
|
418 |
+
## PharmAI: Your Expert Pharmacology Assistant
|
419 |
+
|
420 |
+
Welcome to PharmAI, a specialized chatbot powered by Google's Gemini 2.0 Flash model. PharmAI is designed to provide expert-level information on pharmacology topics, leveraging a large dataset of pharmaceutical knowledge ("PharmKG").
|
421 |
+
|
422 |
+
**Key Features:**
|
423 |
+
|
424 |
+
* **Advanced Pharmacology Insights**: PharmAI provides responses that are structured, detailed, and based on a vast knowledge graph of pharmacology.
|
425 |
+
* **Inference and Reasoning**: The chatbot can handle complex, multi-faceted questions, showcasing its ability to reason and infer from available information.
|
426 |
+
* **Structured Responses**: Responses are organized logically to include definitions, mechanisms of action, indications, dosages, side effects, drug interactions, pharmacokinetics, and references when applicable.
|
427 |
+
* **Thinking Process Display**: You can observe the model's thought process as it generates a response (experimental feature).
|
428 |
+
* **Conversation History**: PharmAI remembers the previous parts of the conversation to provide more accurate and relevant information across multiple turns.
|
429 |
+
* **Streaming Output**: The chatbot streams responses for an interactive experience.
|
430 |
+
|
431 |
+
**How to Use PharmAI:**
|
432 |
+
|
433 |
+
1. **Start a Conversation**: Type your pharmacology question into the input box under the "Chat" tab. The chatbot is specifically designed to handle complex pharmacology inquiries.
|
434 |
+
|
435 |
+
2. **Use Example Prompts**: You can try out the example questions provided to see the model in action. These examples are formulated to challenge the chatbot to exhibit its expertise.
|
436 |
+
|
437 |
+
3. **Example Prompt Guidance**:
|
438 |
+
* **Mechanisms of Action**: Ask about how a specific drug works at the molecular level. Example: "Explain the mechanism of action of Metformin."
|
439 |
+
* **Drug Metabolism**: Inquire about how the body processes drugs. Example: "Explain the interplay between CYP450 enzymes and drug metabolism..."
|
440 |
+
* **Clinical Implications**: Pose questions about the clinical use of drugs in treating specific diseases. Example: "Discuss the mechanism of action and clinical significance of beta-blockers in heart failure..."
|
441 |
+
* **Pathophysiology and Drug Targets**: Ask about diseases, what causes them, and how drugs can treat them. Example: "Explain the pathophysiology of type 2 diabetes and how metformin works..."
|
442 |
+
* **Complex Multi-Drug Interactions**: Pose questions about how one drug can affect another drug in the body.
|
443 |
+
* **Traditional Medicine Perspectives**: Ask about traditional medicine (like Hanbang) approaches to disease and treatment. Example: "Explain effective natural plant substances and their mechanisms for treating Alzheimer's from a Hanbang perspective."
|
444 |
+
|
445 |
+
4. **Review Responses**: The chatbot will then present its response with a "Thinking" section that reveals its internal processing. Then it provides the more structured response, with sections including definition, mechanism of action, indications, etc.
|
446 |
+
|
447 |
+
5. **Clear Conversation**: Use the "Clear Chat" button to start a new session.
|
448 |
+
|
449 |
+
**Important Notes:**
|
450 |
+
|
451 |
+
* The 'thinking' feature is experimental, but it shows the steps the model took when creating the response.
|
452 |
+
* The quality of the response is highly dependent on the user prompt. Please be as descriptive as possible when asking questions to the best results.
|
453 |
+
* This model is focused specifically on pharmacology information, so questions outside this scope may not get relevant answers.
|
454 |
+
* This chatbot is intended as an informational resource and should not be used for medical diagnosis or treatment recommendations. Always consult with a healthcare professional for any medical advice.
|
455 |
+
|
456 |
+
"""
|
457 |
+
)
|
458 |
+
|
459 |
+
|
460 |
+
# Add CSS styling
|
461 |
+
demo.load(lambda: None, _js="""
|
462 |
+
() => {
|
463 |
+
const style = document.createElement('style');
|
464 |
+
style.textContent = `
|
465 |
+
.chatbot-wrapper .message {
|
466 |
+
white-space: pre-wrap; /* for preserving line breaks within the chatbot message */
|
467 |
+
word-wrap: break-word; /* for breaking words when the text length exceed the available area */
|
468 |
+
}
|
469 |
+
`;
|
470 |
+
document.head.appendChild(style);
|
471 |
+
}
|
472 |
+
""")
|
473 |
|
474 |
|
475 |
# Launch the interface
|