File size: 1,378 Bytes
7073eba
7e3c3ff
00d7a2e
07f8c16
007bdd0
4b69c94
 
dcb550c
4b69c94
7e3c3ff
2798e6f
07f8c16
2798e6f
4b69c94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2798e6f
 
827c0a2
4b69c94
827c0a2
 
 
07f8c16
827c0a2
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
import gradio as gr
from transformers import AutoTokenizer, TFBlenderbotForConditionalGeneration
import tensorflow as tf
print("Loading the model......")
model_name = "WICKED4950/Irisonego5"
strategy = tf.distribute.MirroredStrategy()
tf.config.optimizer.set_jit(True)  # Enable XLA
tokenizer = AutoTokenizer.from_pretrained(model_name) 
with strategy.scope():
    model = TFBlenderbotForConditionalGeneration.from_pretrained(model_name)

print("Interface getting done....")
# Define the chatbot function
def predict(user_input):
    # Tokenize input text
    inputs = tokenizer(user_input, return_tensors="tf", padding=True, truncation=True)

    # Generate the response using the model
    response_ids = model.generate(
        inputs['input_ids'],
        max_length=128,         # Set max length of response
        do_sample=True,         # Sampling for variability
        top_k=15,               # Consider top 50 tokens
        top_p=0.95,             # Nucleus sampling
        temperature=0.8         # Adjusts creativity of response
    )

    # Decode the response
    response = tokenizer.decode(response_id[0], skip_special_tokens=True)
    return response

# Gradio interface
iface = gr.Interface(fn=predict, 
                     inputs="text", 
                     outputs="text", 
                     title="Your Chatbot")
print("Deploying")
iface.launch()