-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (60 loc) · 1.96 KB
/
main.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
!pip install transformers
from transformers import pipeline, set_seed
import random
number1 = input('Enter your first number:')
number2 = input('Enter your second number:')
option = input('What do you want to do?(If you do not know ask for "help"):')
# Define functions for each operation
def add(num1, num2):
print(int(num1),"+",int(num2),"=",int(num1) + int(num2))
def subtract(num1, num2):
print(int(num1),"-",int(num2),"=",int(num1) - int(num2))
def multiply(num1, num2):
print(int(num1),"×",int(num2),"=",int(num1) * int(num2))
def divide(num1, num2):
print(int(num1),"÷",int(num2),"=",int(num1) / int(num2))
# Use the function based on user input
if option == 'help':
print('You can ask to: add')
print('You can ask to: subtract')
print('You can ask to: multiply')
print('You can ask to: divide')
print('You can ask for two random numbers: random')
print('You can ask for chatgpt: chatgpt')
print('You can ask for help: help')
print('You can ask to exit: exit')
elif option == 'exit':
print('Exiting...')
exit(1)
elif option == 'add':
add(number1, number2)
exit(1)
elif option == 'subtract':
subtract(number1, number2)
exit(1)
elif option == 'multiply':
multiply(number1, number2)
exit(1)
elif option == 'divide':
divide(number1, number2)
exit(1)
elif option == 'random':
number1 = random.randint(1,10)
number2 = random.randint(1,10)
print(number1,"and",number2)
exit(1)
elif option == 'chatgpt':
generator = pipeline('text-generation', model='gpt2')
set_seed(42)
def chatbot_response(prompt):
"""Generates a response to a user prompt using the GPT-2 model."""
response = generator(prompt, max_length=150, num_return_sequences=1)
return response[0]['generated_text']
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
break
bot_response = chatbot_response(user_input)
print("Bot:", bot_response)
else:
print('invalid input')