Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +68 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pdfplumber
|
| 3 |
+
import docx
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import openai
|
| 7 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
+
|
| 9 |
+
def extract_text_from_file(file):
|
| 10 |
+
if file.name.endswith(".pdf"):
|
| 11 |
+
with pdfplumber.open(file.name) as pdf:
|
| 12 |
+
return "\n".join(page.extract_text() for page in pdf.pages if page.extract_text())
|
| 13 |
+
elif file.name.endswith(".docx"):
|
| 14 |
+
doc = docx.Document(file.name)
|
| 15 |
+
return "\n".join([p.text for p in doc.paragraphs])
|
| 16 |
+
elif file.name.endswith(".txt"):
|
| 17 |
+
return file.read().decode("utf-8")
|
| 18 |
+
else:
|
| 19 |
+
return "Unsupported file type."
|
| 20 |
+
|
| 21 |
+
def generate_content(tek_text):
|
| 22 |
+
prompt = f"""
|
| 23 |
+
You are an AI education assistant. The following is a list of TEKS (Texas Essential Knowledge and Skills) or similar learning standards:
|
| 24 |
+
|
| 25 |
+
{tek_text}
|
| 26 |
+
|
| 27 |
+
For each TEK or standard, generate:
|
| 28 |
+
1. A short summary or note explaining the concept.
|
| 29 |
+
2. A list of 3-5 important vocabulary words.
|
| 30 |
+
3. 2-3 practice problems (multiple choice, fill in the blank, or short answer).
|
| 31 |
+
|
| 32 |
+
Format:
|
| 33 |
+
TEK: <actual text>
|
| 34 |
+
Notes: <summary>
|
| 35 |
+
Vocabulary: <words>
|
| 36 |
+
Practice Problems:
|
| 37 |
+
1. <question>
|
| 38 |
+
2. <question>
|
| 39 |
+
---
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
response = openai.ChatCompletion.create(
|
| 43 |
+
model="gpt-4",
|
| 44 |
+
messages=[{"role": "user", "content": prompt}],
|
| 45 |
+
temperature=0.7
|
| 46 |
+
)
|
| 47 |
+
return response["choices"][0]["message"]["content"]
|
| 48 |
+
|
| 49 |
+
def process_file(file):
|
| 50 |
+
teks_text = extract_text_from_file(file)
|
| 51 |
+
if teks_text.startswith("Unsupported"):
|
| 52 |
+
return teks_text
|
| 53 |
+
return generate_content(teks_text)
|
| 54 |
+
|
| 55 |
+
with gr.Blocks() as demo:
|
| 56 |
+
gr.Markdown("""# 📚 TEKS Learning Generator
|
| 57 |
+
Upload a TEKS or learning standard document (PDF, DOCX, or TXT), and the AI will generate notes, vocabulary, and practice problems for each TEK.
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
file_input = gr.File(label="Upload TEKS Document")
|
| 62 |
+
output = gr.Textbox(label="AI-Generated Output", lines=30)
|
| 63 |
+
|
| 64 |
+
submit_btn = gr.Button("Generate Learning Content")
|
| 65 |
+
submit_btn.click(fn=process_file, inputs=file_input, outputs=output)
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
openai
|
| 3 |
+
pdfplumber
|
| 4 |
+
python-docx
|