File size: 1,066 Bytes
cc70292
 
eeedcbc
 
 
 
cc70292
eeedcbc
cc70292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1363fd6
 
cc70292
1363fd6
cc70292
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
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Install SentencePiece
import sentencepiece
import torch

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("ahmed792002/Finetuning_T5_HealthCare_Chatbot", use_fast=True)
model = AutoModelForSeq2SeqLM.from_pretrained("ahmed792002/Finetuning_T5_HealthCare_Chatbot")

# Define the chatbot function
def chatbot(input_text):
    inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)
    outputs = model.generate(inputs["input_ids"], max_length=100, num_beams=4, early_stopping=True)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response

# Set up the Gradio interface
interface = gr.Interface(
    fn=chatbot,
    inputs=gr.inputs.Textbox(label="Enter your query"),
    outputs=gr.outputs.Textbox(label="Response"),
    title="Healthcare Chatbot",
    description="Ask healthcare-related questions, and get responses from the fine-tuned T5 model."
)

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