Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
-
# Load model
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
|
| 6 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
-
return result
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
iface = gr.Interface(
|
| 19 |
fn=generate_notes,
|
| 20 |
-
inputs=gr.Textbox(lines=
|
| 21 |
-
outputs="
|
| 22 |
-
title="
|
| 23 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|