File size: 1,151 Bytes
c744265
9f5f8f8
51f5182
c744265
021e6cc
 
a030d30
7d47e29
021e6cc
 
 
 
 
 
 
 
 
 
 
1e125e4
7d47e29
021e6cc
 
 
 
1fdb6cd
9f5f8f8
 
51f5182
1fdb6cd
9f5f8f8
dbdc36a
c744265
021e6cc
51f5182
c744265
 
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
import gradio as gr
import random
#import lines go at the top!

from huggingface_hub import InferenceClient

client = InferenceClient("microsoft/phi-4")
# name of llm chatbot accessed ^^ or can use ' microsoft/phi-4 that's connected to the microsoft phi gen model

def respond(message,history):

    messages = [{'role': 'system','content':'You are a friendly chatbot.'}]
    #creating dictionary containing key value pairs; first key value pair is system message, second is user message

    if history:
        messages.extend(history)

    messages.append({'role': 'user','content': message})

    response = client.chat_completion(messages, max_tokens = 500, top_p=0.8)
    #max tokens is a parameter to determine how long the message should be

    return response['choices'][0]['message']['content'].strip()

#def yes_or_no(message,history):
#    return random.choice(['Yes','No'])
    
#def echo(message, history):
    #always need two inputs
#	return message
 
#print("Hello, World")

chatbot = gr.ChatInterface(respond, type='messages')
#defining my chatbot so user can interact, see their conversation and send new messages

chatbot.launch()