File size: 1,058 Bytes
9f10e3f
2598fe4
620f406
 
 
dc96b40
9f10e3f
dc96b40
 
 
2598fe4
 
620f406
2598fe4
 
50960e5
620f406
 
 
 
 
 
 
 
 
 
 
 
 
 
2c5331e
620f406
2598fe4
 
620f406
dc96b40
9f10e3f
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
30
31
32
33
34
35
36
37
38
import gradio as gr # imports the gradio library
import random
from huggingface_hub import InferenceClient

client = InferenceClient("microsoft/phi-4")

# returns the message back to the user
def echo(message, history):
    return message

# returns yes or no back to the user
def yes_or_no(message, history):
    
    responses = ["Yes","No"]
    return random.choice(responses) #randomly returns one

# returns a message back to the user
def response(message, history):

    messages = [{"role":"system","content":"You are a friendly chatbot :)"}]

    if history:
        messages.extend(history)

    messages.append({"role":"user", "content":message})
    responses = client.chat_completion(
        messages,
        max_tokens = 100 #chunks of material
    )
    
    return responses['choices'][0]['message']['content'].strip() #returns response from library

#print("Hello world!") #prints in the logs

chatbot = gr.ChatInterface(response, type="messages", title="chatbot bestie") # chatbout ui - history & input

chatbot.launch() # lauches chatbot