arpit13 commited on
Commit
e092bde
·
verified ·
1 Parent(s): 5ba3474

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ # Load model and tokenizer
6
+ model_name = "SJSui/AstroBot"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+
10
+ # Function to generate text
11
+ def generate_text(prompt):
12
+ inputs = tokenizer(prompt, return_tensors="pt")
13
+ with torch.no_grad():
14
+ output = model.generate(**inputs, max_length=100)
15
+ return tokenizer.decode(output[0], skip_special_tokens=True)
16
+
17
+ # Gradio Interface
18
+ iface = gr.Interface(
19
+ fn=generate_text,
20
+ inputs=gr.Textbox(label="Enter your prompt"),
21
+ outputs=gr.Textbox(label="Generated Response"),
22
+ title="AstroBot AI Chat",
23
+ description="This is a chatbot powered by the AstroBot model.",
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ iface.launch()