ivmpfa commited on
Commit
2d839f4
·
verified ·
1 Parent(s): 4d8c4fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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, # Maximum response length
9
- temperature=0.7, # Creativity (0.0 = deterministic, 1.0 = random)
10
- early_stopping=True, # Stop generation early if possible
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():