File size: 885 Bytes
73f567e
 
 
 
d754113
73f567e
 
d754113
 
73f567e
d754113
 
 
 
 
 
 
 
 
 
 
73f567e
d754113
 
73f567e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()