IEEEVITPune-AI-Team commited on
Commit
81f3c54
1 Parent(s): 433bfc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -1,3 +1,22 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/IEEEVITPune-AI-Team/ChatbotAlpha0.7").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
 
4
+ # Load the model and tokenizer
5
+ model_name = "IEEEVITPune-AI-Team/ChatbotAlpha0.7"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Define the function to generate response
10
+ def generate_response(prompt):
11
+ instruction = f"### Instruction:\n{prompt}\n\n### Response:\n"
12
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=256)
13
+ result = pipe(instruction)
14
+ generated_text = result[0]['generated_text'][len(instruction):].strip()
15
+ return generated_text
16
+
17
+ # Create a Gradio interface
18
+ input_text = gr.inputs.Textbox(lines=3, label="Enter your prompt")
19
+ output_text = gr.outputs.Textbox(label="Response")
20
+
21
+ gr.Interface(generate_response, inputs=input_text, outputs=output_text, title="Chatbot", description="What is IEEE?.").launch()
22
+ ad("models/IEEEVITPune-AI-Team/ChatbotAlpha0.7").launch()