Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| from huggingface_hub import InferenceClient | |
| from gradio.themes.utils import colors | |
| theme = gr.themes.Default( | |
| primary_hue=gr.themes.Color( | |
| c100="#ffedd5", c200="#fed7aa", c300="#ffe09e", c400="#c2814c", | |
| c50="#fff8f0", c500="#f97316", c600="#ea580c", c700="#c2410c", | |
| c800="#9a3412", c900="#7c2d12", c950="#611f00" | |
| ), | |
| secondary_hue="red", | |
| neutral_hue="slate", | |
| font=[gr.themes.GoogleFont('jack armstrong'), 'ui-sans-serif', 'system-ui', 'sans-serif'], | |
| font_mono=[gr.themes.GoogleFont('xkcd'), 'ui-monospace', 'Consolas', 'monospace'], | |
| ).set( | |
| body_text_color='*primary_950', | |
| body_text_color_dark='*secondary_50', | |
| body_text_size='26px', # Increase body text size | |
| body_text_color_subdued='*primary_400', | |
| body_text_weight='500', | |
| background_fill_primary='*primary_300', | |
| background_fill_primary_dark='*primary_800', | |
| background_fill_secondary='*primary_50', | |
| background_fill_secondary_dark='*primary_600', | |
| border_color_accent='*secondary_950', | |
| border_color_accent_dark='*body_text_color', | |
| border_color_accent_subdued='*border_color_accent', | |
| link_text_color='*secondary_800', | |
| code_background_fill='*neutral_200', | |
| code_background_fill_dark='*neutral_100', | |
| block_shadow='none', | |
| block_shadow_dark='none', | |
| form_gap_width='0px', | |
| checkbox_label_background_fill='*button_secondary_background_fill', | |
| checkbox_label_background_fill_dark='*button_secondary_background_fill', | |
| checkbox_label_background_fill_hover='*button_secondary_background_fill_hover', | |
| checkbox_label_background_fill_hover_dark='*button_secondary_background_fill_hover', | |
| checkbox_label_shadow='none', | |
| error_background_fill_dark='*background_fill_primary', | |
| input_background_fill='*neutral_100', | |
| input_background_fill_dark='*neutral_700', | |
| input_border_width='0px', | |
| input_border_width_dark='0px', | |
| input_shadow='none', | |
| input_shadow_dark='none', | |
| input_shadow_focus='*input_shadow', | |
| input_shadow_focus_dark='*input_shadow', | |
| stat_background_fill='*primary_300', | |
| stat_background_fill_dark='*primary_500', | |
| button_shadow='none', | |
| button_shadow_active='none', | |
| button_shadow_hover='none', | |
| button_transition='background-color 0.2s ease', | |
| button_primary_background_fill='*primary_200', | |
| button_primary_background_fill_dark='*primary_700', | |
| button_primary_background_fill_hover='*button_primary_background_fill', | |
| button_primary_background_fill_hover_dark='*button_primary_background_fill', | |
| button_primary_border_color_dark='*primary_600', | |
| button_secondary_background_fill='*neutral_200', | |
| button_secondary_background_fill_dark='*neutral_600', | |
| button_secondary_background_fill_hover='*button_secondary_background_fill', | |
| button_secondary_background_fill_hover_dark='*button_secondary_background_fill', | |
| button_cancel_background_fill='*button_secondary_background_fill', | |
| button_cancel_background_fill_dark='*button_secondary_background_fill', | |
| button_cancel_background_fill_hover='*button_cancel_background_fill', | |
| button_cancel_background_fill_hover_dark='*button_cancel_background_fill', | |
| button_cancel_border_color='*button_secondary_border_color', | |
| button_cancel_border_color_dark='*button_secondary_border_color', | |
| button_cancel_text_color='*button_secondary_text_color', | |
| button_cancel_text_color_dark='*button_secondary_text_color' | |
| ) | |
| client = InferenceClient ("HuggingFaceH4/zephyr-7b-beta") #change the LLM | |
| def respond(message, history): | |
| messages = [{"role" : "system", "content" : "You are a chatbot who helps with mental health"}] #change personality | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role" : "user", "content" : message}) | |
| response = "" | |
| for message in client.chat_completion( | |
| messages, | |
| max_tokens = 100, #change length | |
| stream =True | |
| ): | |
| token = message.choices[0].delta.content | |
| response += token | |
| print(type(message)) | |
| print(response) | |
| yield response | |
| #print(response["choices"][0]["message"]["content"].strip()) | |
| def random_message(message, history): | |
| choices = ["try again later", "isn't looking good for you", "perhaps", "maybe", "doubtful", "yes", "no", "without a doubt", "most likely", "signs point to yes", "it is certain", "my sources say no", "reply hazy, try again"] | |
| random_choices = random.choice(choices) | |
| return random_choices | |
| chatbot = gr.ChatInterface(respond, type = "messages", theme=theme) | |
| chatbot.launch(debug=True) |