File size: 1,463 Bytes
ec9ef8b
f24bed6
6c23478
f24bed6
6c23478
 
ec9ef8b
6c23478
ec9ef8b
 
 
 
 
 
 
f24bed6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
import gradio as gr
#from transformers import pipeline

"""
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")

def predict(image):
    predictions = pipeline(image)
    return {p["label"]: p["score"] for p in predictions}

gr.Interface(
    predict,
    inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
    outputs=gr.outputs.Label(num_top_classes=2),
    title="Hot Dog? Or Not?",
).launch()
"""

from transformers import AutoModelForCausalLM, AutoTokenizer

def chatbot_response(user_message):
    # Load the pre-trained model and tokenizer
    model_name = "your_pretrained_model_name"  # Replace with the name of the pre-trained model you want to use
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)

    # Tokenize the user's message and generate the response
    inputs = tokenizer.encode("User: " + user_message, return_tensors="pt")
    outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return response

if __name__ == '__main__':
    print("Chatbot: Hello! I'm your chatbot. Type 'exit' to end the conversation.")
    
    while True:
        user_input = input("You: ")
        
        if user_input.lower() == 'exit':
            break

        response = chatbot_response(user_input)
        print("Chatbot:", response)