Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
# Load GPT-2 with optimized parameters
|
| 5 |
model = pipeline(
|
| 6 |
"text-generation",
|
| 7 |
model="gpt2",
|
| 8 |
-
max_length=200,
|
| 9 |
-
temperature=0.7,
|
| 10 |
-
early_stopping=True,
|
| 11 |
torch_dtype=torch.float32 # CPU compatibility
|
| 12 |
)
|
| 13 |
|
| 14 |
def chat_with_gpt2(user_input):
|
| 15 |
-
# Generate a response based on user input
|
| 16 |
prompt = f"{user_input}"
|
| 17 |
try:
|
| 18 |
with torch.no_grad():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import torch # <-- ADD THIS LINE
|
| 4 |
|
| 5 |
# Load GPT-2 with optimized parameters
|
| 6 |
model = pipeline(
|
| 7 |
"text-generation",
|
| 8 |
model="gpt2",
|
| 9 |
+
max_length=200,
|
| 10 |
+
temperature=0.7,
|
| 11 |
+
early_stopping=True,
|
| 12 |
torch_dtype=torch.float32 # CPU compatibility
|
| 13 |
)
|
| 14 |
|
| 15 |
def chat_with_gpt2(user_input):
|
|
|
|
| 16 |
prompt = f"{user_input}"
|
| 17 |
try:
|
| 18 |
with torch.no_grad():
|