migueldeguzmandev commited on
Commit
c919b63
1 Parent(s): 6b85548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -2,17 +2,28 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
  # Load the model and tokenizer
5
- model_name = "migueldeguzmandev/RLLMv3.2-10"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
 
 
 
9
  # Define the inference function
10
- def generate_response(input_text):
11
  # Tokenize the input text
12
- input_ids = tokenizer.encode(input_text, return_tensors="pt")
 
 
13
 
14
  # Generate the model's response
15
- output = model.generate(input_ids, max_length=300, num_return_sequences=1)
 
 
 
 
 
 
16
 
17
  # Decode the generated response
18
  response = tokenizer.decode(output[0], skip_special_tokens=True)
@@ -22,11 +33,14 @@ def generate_response(input_text):
22
  # Create the Gradio interface
23
  interface = gr.Interface(
24
  fn=generate_response,
25
- inputs=gr.Textbox(label="User Input"),
 
 
 
26
  outputs=gr.Textbox(label="Model Response"),
27
- title="Conversation with a modified GPT2XL, RLLMv3.2-10",
28
- description="Enter your message and the model will generate a response.",
29
  )
30
 
31
- # Launch the interface
32
- interface.launch()
 
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
  # Load the model and tokenizer
5
+ model_name = "migueldeguzmandev/migueldeguzmandev-RLLMv3.2-10"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
+ # Set the pad token ID to the EOS token ID
10
+ model.config.pad_token_id = model.config.eos_token_id
11
+
12
  # Define the inference function
13
+ def generate_response(input_text, temperature):
14
  # Tokenize the input text
15
+ inputs = tokenizer(input_text, return_tensors="pt")
16
+ input_ids = inputs["input_ids"]
17
+ attention_mask = inputs["attention_mask"]
18
 
19
  # Generate the model's response
20
+ output = model.generate(
21
+ input_ids,
22
+ attention_mask=attention_mask,
23
+ max_length=1024,
24
+ num_return_sequences=1,
25
+ temperature=temperature,
26
+ )
27
 
28
  # Decode the generated response
29
  response = tokenizer.decode(output[0], skip_special_tokens=True)
 
33
  # Create the Gradio interface
34
  interface = gr.Interface(
35
  fn=generate_response,
36
+ inputs=[
37
+ gr.Textbox(label="User Input"),
38
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.0000000000000000000000000000001, step=0.1, label="Temperature"),
39
+ ],
40
  outputs=gr.Textbox(label="Model Response"),
41
+ title="Conversation with migueldeguzmandev-RLLMv3.2-10",
42
+ description="Enter your message and adjust the temperature, then the model will generate a response.",
43
  )
44
 
45
+ # Launch the interface with the share option set to True
46
+ interface.launch(share=True)