ginipick commited on
Commit
e0edbaf
Β·
verified Β·
1 Parent(s): 6aa40e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -0
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