rrk757's picture
Update app.py
df8837b verified
from huggingface_hub import InferenceClient
import gradio as gr
import random
client = InferenceClient("google/gemma-3-27b-it")
#this is where you change the LLM
def respond(message,history):
if "nearest obgyn" in message.lower():
# Return a custom response (for UI to act on)
return "Sure! Please click on the 'OBGYN Finder' tab above to get started. ๐Ÿฉบ", history
messages = [{"role": "system", "content": "You are a mean chatbot."}]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
response = ""
for message in client.chat_completion(
messages,
max_tokens=50,
stream=True
):
token = message.choices[0].delta.content
response += token
yield response
#temperature=.9,
#top_p=.7) #changes the length of message
def echo(message, history):
choices = ["so true", "shut up", "you need help", "ts pmo sybau"] #change personality
#use random to select choices
chat_answer = random.choice(choices)
return chat_answer
def show_info(topic):
responses = {
"Puberty": "Puberty is when your body begins to change into an adult body.",
"Periods": "A period is a natural process where the body sheds the uterine lining.",
"Hormones": "Hormones are chemicals that regulate body functions, mood, and growth.",
"Self-care": "Self-care means taking time to rest, eat well, and manage stress."
}
return responses.get(topic, "Select a topic to see more info.")
with gr.Blocks() as demo:
gr.Markdown("## ๐Ÿ’ฌ Mean Chatbot")
user_input = gr.Textbox(label="Your Question", placeholder="Type something...", lines=2)
output = gr.Textbox(label="Bot's Answer", interactive=False)
state = gr.State([])
def show_info
def handle_submit(message, history):
response = ""
for partial in respond(message, history):
response = partial
yield response
user_input.submit(
fn=handle_submit,
inputs=[user_input, state],
outputs=output
)
with gr.Tab("Tab 1"):
gr.Markdown("### This is Tab 1")
gr.HTML("""
<a href="https://drive.google.com/file/d/1_KNELAUDLLidwAT3fs2JBuO1yPgMGoDv/view" target="_blank">
<button style="font-size:16px;padding:10px 20px;margin-top:10px;">
๐Ÿ“„ Open Puberty Guide PDF
</button>
</a>
""")
with gr.Tab("OBGYN Finder") as obgyn_tab:
gr.Markdown("### Find a Nearby OBGYN")
location_dropdown = gr.Dropdown(
choices=["New York", "California", "Texas", "Florida"],
label="Choose your state"
)
result_text = gr.Textbox(label="Nearby Clinics")
# Show response when a choice is made
dropdown.change(fn=show_info, inputs=dropdown, outputs=output)
demo.launch(debug=True)
#added code for blocks
#chatbot = gr.ChatInterface(respond, type = "messages")
#chatbot.launch()
#chatbot.launch(debug=True)