File size: 1,639 Bytes
178d292
9da12bd
178d292
9da12bd
 
 
178d292
0176578
 
 
9da12bd
a9c61c0
e6a2ee9
555a102
 
a9c61c0
 
 
 
0176578
 
 
 
 
 
 
 
 
 
 
a9c61c0
 
 
 
 
 
 
178d292
9da12bd
 
178d292
9da12bd
178d292
9da12bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

# Load your model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("sammanamgain/callcenter_response")
model = AutoModelForCausalLM.from_pretrained("sammanamgain/callcenter_response")

# Set pad_token_id to eos_token_id
model.config.pad_token_id = model.config.eos_token_id

def generate_response(prompt):
    # Use a special separator token or pattern
    instruction = "how to open a account"
   
    input_text = f"{prompt}"

    # Tokenize the input and create the attention mask
    inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)

    # Generate response with adjusted parameters
    generated_ids = model.generate(
        inputs['input_ids'], 
        attention_mask=inputs['attention_mask'], 
        max_new_tokens=200,  # Adjusted to a reasonable token count for response length
        do_sample=True, 
        top_k=50,  # Adjust top-k sampling
        top_p=0.95,  # Adjust top-p sampling
        temperature=0.7,  # Adjust temperature
        pad_token_id=model.config.eos_token_id  # Explicitly set pad_token_id
    )

    # Decode the generated tokens
    result = tokenizer.decode(generated_ids[0], skip_special_tokens=True)

    # Remove the input part from the result by splitting at the special token
    response = result.split('[SEP]')[-1].strip()
    return response

# Define the Gradio interface
interface = gr.Interface(fn=generate_response, inputs="text", outputs="text", title="Call Center Response Generator")

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch()