Talhaalvi12 commited on
Commit
c844eeb
·
verified ·
1 Parent(s): d00c9b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -1,26 +1,43 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
- # Load model and tokenizer
5
  tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
6
  model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
7
 
8
- # Note generator function
9
- def generate_notes(prompt):
10
- # Add task prefix for FLAN-T5
11
- input_text = f"Summarize or make concise notes: {prompt}"
12
- inputs = tokenizer(input_text, return_tensors="pt", truncation=True)
13
- outputs = model.generate(**inputs, max_new_tokens=200)
14
- result = tokenizer.decode(outputs[0], skip_special_tokens=True)
15
- return result
16
 
17
- # Gradio interface
 
 
 
 
 
 
 
 
 
 
 
18
  iface = gr.Interface(
19
  fn=generate_notes,
20
- inputs=gr.Textbox(lines=5, placeholder="Enter your topic or text here..."),
21
- outputs="text",
22
- title="🧠 Free Note Generator (FLAN-T5-small)",
23
- description="Generate summarized notes using Google's FLAN-T5-small model — runs 100% free on CPU in Hugging Face Spaces."
 
 
 
 
 
 
 
 
24
  )
25
 
26
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
+ # Load lightweight model
5
  tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
6
  model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
7
 
8
+ def generate_notes(topic):
9
+ """
10
+ Takes a topic string and generates study-style notes.
11
+ """
12
+ if not topic.strip():
13
+ return "⚠️ Please enter a topic first."
 
 
14
 
15
+ prompt = (
16
+ f"Create clear, structured study notes about the topic '{topic}'. "
17
+ f"Include definitions, key points, and examples if possible. "
18
+ f"Keep it concise and easy to understand."
19
+ )
20
+
21
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
22
+ outputs = model.generate(**inputs, max_new_tokens=250, temperature=0.7, top_p=0.9)
23
+ notes = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
+ return notes
25
+
26
+ # Gradio UI
27
  iface = gr.Interface(
28
  fn=generate_notes,
29
+ inputs=gr.Textbox(lines=2, placeholder="Enter a topic (e.g. Photosynthesis, Quantum Physics)"),
30
+ outputs=gr.Textbox(label="Generated Notes", lines=10),
31
+ title="📘 AI Note Generator",
32
+ description=(
33
+ "Enter any topic and get concise, well-structured notes generated by "
34
+ "a free open-source model (FLAN-T5-small)."
35
+ ),
36
+ examples=[
37
+ ["The water cycle"],
38
+ ["Machine learning"],
39
+ ["World War II"]
40
+ ]
41
  )
42
 
43
  iface.launch()