Spaces:
Runtime error
Runtime error
SusiePHaltmann
commited on
Commit
•
2dfd879
1
Parent(s):
b087f1f
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,41 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
-
|
10 |
-
def chat(input_text):
|
11 |
try:
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
# Launch the interface
|
33 |
if __name__ == "__main__":
|
34 |
-
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
|
4 |
+
# Check for required modules
|
5 |
+
required_modules = ['transformers', 'torch', 'numpy']
|
|
|
|
|
6 |
|
7 |
+
for module in required_modules:
|
|
|
8 |
try:
|
9 |
+
__import__(module)
|
10 |
+
except ImportError:
|
11 |
+
print(f"Module '{module}' not found. Installing...")
|
12 |
+
os.system(f"{sys.executable} -m pip install {module}")
|
13 |
+
|
14 |
+
# Import necessary libraries
|
15 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
16 |
+
import torch
|
17 |
+
import numpy as np
|
18 |
+
|
19 |
+
# Setup model and tokenizer
|
20 |
+
model_name = "gpt-3.5-turbo" # You might want to replace this with your specific model
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
22 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
23 |
|
24 |
+
# Function to generate text
|
25 |
+
def generate_text(prompt, max_length=100):
|
26 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
27 |
+
outputs = model.generate(inputs.input_ids, max_length=max_length, do_sample=True, top_k=50, top_p=0.95)
|
28 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
|
30 |
+
# Main function
|
31 |
+
def main():
|
32 |
+
print("Welcome to CATGPT! Type 'exit' to quit.")
|
33 |
+
while True:
|
34 |
+
prompt = input("\nEnter your prompt: ")
|
35 |
+
if prompt.lower() == 'exit':
|
36 |
+
break
|
37 |
+
response = generate_text(prompt)
|
38 |
+
print(f"\nCATGPT: {response}")
|
39 |
|
|
|
40 |
if __name__ == "__main__":
|
41 |
+
main()
|