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