studentsonug commited on
Commit
9dde3fd
·
verified ·
1 Parent(s): 9675b54

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
+
5
+ # Model aur tokenizer load karo
6
+ model_name = "google/flan-t5-base"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
+
10
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
11
+
12
+ def generate_text(prompt):
13
+ inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True).to(device)
14
+ outputs = model.generate(
15
+ **inputs,
16
+ max_new_tokens=200,
17
+ temperature=0.7,
18
+ top_p=0.9
19
+ )
20
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+
22
+ # Gradio UI
23
+ demo = gr.Interface(
24
+ fn=generate_text,
25
+ inputs=gr.Textbox(lines=3, placeholder="Enter your prompt here..."),
26
+ outputs="text",
27
+ title="FLAN-T5 Text Generation (GPU Enabled)",
28
+ description="Google FLAN-T5-Base deployed on Hugging Face Spaces with GPU support."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()