styx102 commited on
Commit
b7630be
·
verified ·
1 Parent(s): 504e17a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -2,9 +2,9 @@ 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"):
@@ -39,12 +39,15 @@ Practice Problems:
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)
@@ -53,9 +56,7 @@ def process_file(file):
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")
 
2
  import pdfplumber
3
  import docx
4
  import os
 
5
  import openai
6
+
7
+ client = openai.OpenAI() # Uses OPENAI_API_KEY from environment
8
 
9
  def extract_text_from_file(file):
10
  if file.name.endswith(".pdf"):
 
39
  ---
40
  """
41
 
42
+ response = client.chat.completions.create(
43
+ model="gpt-3",
44
+ messages=[
45
+ {"role": "system", "content": "You are a helpful AI educator."},
46
+ {"role": "user", "content": prompt}
47
+ ],
48
  temperature=0.7
49
  )
50
+ return response.choices[0].message.content
51
 
52
  def process_file(file):
53
  teks_text = extract_text_from_file(file)
 
56
  return generate_content(teks_text)
57
 
58
  with gr.Blocks() as demo:
59
+ 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.")
 
 
60
 
61
  with gr.Row():
62
  file_input = gr.File(label="Upload TEKS Document")