kdevoe commited on
Commit
5b2a7b6
·
verified ·
1 Parent(s): 4d1575b

Adding sliders for temp, top_p and top_k

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -26,13 +26,12 @@ model.to(device)
26
  # Set up conversational memory using LangChain's ConversationBufferMemory
27
  memory = ConversationBufferMemory()
28
 
29
- # Define the chatbot function with memory
30
- def chat_with_distilgpt2(input_text):
31
  # Retrieve conversation history
32
  conversation_history = memory.load_memory_variables({})['history']
33
 
34
  # Combine the (possibly summarized) history with the current user input
35
- #full_input = f"{conversation_history}\nUser: {input_text}\nAssistant:"
36
  no_memory_input = f"Question: {input_text}\nAnswer:"
37
 
38
  # Tokenize the input and convert to tensor
@@ -48,7 +47,10 @@ def chat_with_distilgpt2(input_text):
48
  repetition_penalty=1.2,
49
  early_stopping=True,
50
  pad_token_id=tokenizer.eos_token_id,
51
- eos_token_id=tokenizer.eos_token_id
 
 
 
52
  )
53
 
54
  # Decode the model output
@@ -59,20 +61,20 @@ def chat_with_distilgpt2(input_text):
59
 
60
  return response
61
 
62
- # Set up the Gradio interface
63
  interface = gr.Interface(
64
  fn=chat_with_distilgpt2,
65
- inputs=gr.Textbox(label="Chat with DistilGPT-2"),
66
- outputs=gr.Textbox(label="DistilGPT-2's Response"),
67
- title="DistilGPT-2 Chatbot with Memory",
68
- description="This is a simple chatbot powered by the DistilGPT-2 model with conversational memory, using LangChain.",
 
 
 
 
 
69
  )
70
 
71
  # Launch the Gradio app
72
  interface.launch()
73
 
74
-
75
-
76
-
77
-
78
-
 
26
  # Set up conversational memory using LangChain's ConversationBufferMemory
27
  memory = ConversationBufferMemory()
28
 
29
+ # Define the chatbot function with memory and additional parameters
30
+ def chat_with_distilgpt2(input_text, temperature, top_p, top_k):
31
  # Retrieve conversation history
32
  conversation_history = memory.load_memory_variables({})['history']
33
 
34
  # Combine the (possibly summarized) history with the current user input
 
35
  no_memory_input = f"Question: {input_text}\nAnswer:"
36
 
37
  # Tokenize the input and convert to tensor
 
47
  repetition_penalty=1.2,
48
  early_stopping=True,
49
  pad_token_id=tokenizer.eos_token_id,
50
+ eos_token_id=tokenizer.eos_token_id,
51
+ temperature=temperature, # Add temperature from slider
52
+ top_p=top_p, # Add top_p from slider
53
+ top_k=top_k # Add top_k from slider
54
  )
55
 
56
  # Decode the model output
 
61
 
62
  return response
63
 
64
+ # Set up the Gradio interface with additional sliders
65
  interface = gr.Interface(
66
  fn=chat_with_distilgpt2,
67
+ inputs=[
68
+ gr.Textbox(label="Chat with DistilGPT-2"), # User input text
69
+ gr.Slider(0.1, 1.0, step=0.1, value=1.0, label="Temperature"), # Slider for temperature
70
+ gr.Slider(0.0, 1.0, step=0.1, value=1.0, label="Top-p"), # Slider for top-p
71
+ gr.Slider(1, 100, step=1, value=50, label="Top-k") # Slider for top-k
72
+ ],
73
+ outputs=gr.Textbox(label="DistilGPT-2's Response"), # Model response
74
+ title="DistilGPT-2 Chatbot with Memory and Adjustable Parameters",
75
+ description="This is a simple chatbot powered by the DistilGPT-2 model with conversational memory, using LangChain. You can adjust temperature, top-p, and top-k using the sliders.",
76
  )
77
 
78
  # Launch the Gradio app
79
  interface.launch()
80