Week1Assignment / app.py
WSLINMSAI's picture
Update app.py
d754113 verified
raw
history blame contribute delete
885 Bytes
import gradio as gr
from huggingface_hub import InferenceClient
"""
This chatbot provides a welcome message and counts the number of words in the sentences you enter.
"""
# Initialize the InferenceClient (if needed, adjust or remove based on your setup)
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
# Define the response function
def count_words(message, history):
if history is None or len(history) == 0:
# Welcome message on first input
return "Hello, I am a Chatbot and can provide you a quick count of how many words are in your sentences!"
else:
# Count the number of words in the message
word_count = len(message.split())
return f"Your sentence contains {word_count} words."
# Set up the Gradio interface
demo = gr.ChatInterface(
count_words,
type="messages"
)
if __name__ == "__main__":
demo.launch()