Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| from huggingface_hub import InferenceClient | |
| # IMPORT INFERENCE CLIENT | |
| # import lines go at the top! Any libraries I need to import go up here ^^ | |
| client = InferenceClient("microsoft/phi-4") | |
| # CREATE AN INSTANCE OF INFERENCE CLIENT THAT'S CONNECTED TO THE MICROSOFT PHI GENERATION MODEL | |
| def respond(message, history): | |
| messages = [{"role": "system", "content": "You are a friendly chatbot."}] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion( | |
| messages, | |
| max_tokens=100 | |
| ) | |
| return response['choices'][0]['message']['content'].strip() | |
| # CODE NEW RESPOND FUNCTION | |
| #def magic_8_ball(message,history): | |
| # return random.choice(['Maybe', "I don't think so honey", "Yea right", "Absolutely!", "I can see that for you.", "ijbol"]) | |
| # def yes_or_no(message, history): | |
| # return random.choice(['Yes', 'No']) | |
| # def echo(message, history): | |
| # return message | |
| print("Hello World!") | |
| chatbot = gr.ChatInterface( | |
| respond, # CHANGE THE FUNCTION MY CHATBOT RUNS | |
| #title="The Psychic Magic 8 Ball!", | |
| #description="Ask any yes or no question to learn your future", | |
| type="messages" | |
| ) | |
| # defining my chatbot so that the user can interact, see their conversation history and send new messages | |
| chatbot.launch() |