mohammed3536 commited on
Commit
1bb215c
1 Parent(s): 1370400

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -1,14 +1,18 @@
1
  import PyPDF2
2
  import nltk
 
3
  import random
 
4
  import streamlit as st
5
  from langchain_openai import OpenAI
6
 
7
  # Download NLTK data (if not already downloaded)
8
  nltk.download('punkt')
 
9
 
10
- # LangChain OpenAI wrapper
11
- openai = OpenAI(api_key="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")
 
12
 
13
  def extract_text_from_pdf(pdf_file):
14
  pdf_reader = PyPDF2.PdfReader(pdf_file)
@@ -33,6 +37,13 @@ def generate_mcqs_on_topic(text, topic, num_mcqs=5):
33
  return mcqs
34
 
35
  def generate_question_with_chatgpt(context):
 
 
 
 
 
 
 
36
  # Initializing the default value
37
  generated_question = {
38
  'content': "Unable to generate a question..",
@@ -50,7 +61,7 @@ def generate_question_with_chatgpt(context):
50
  ],
51
  }
52
 
53
- response = openai.ChatCompletion.create(data)
54
  result = response.json()
55
 
56
  print("API Response:", result) # Add this line for debugging
@@ -67,6 +78,7 @@ def generate_question_with_chatgpt(context):
67
 
68
  return generated_question
69
 
 
70
  def main():
71
  # Title of the Application
72
  st.header("🤖CB Quiz Generator🧠", divider='rainbow')
 
1
  import PyPDF2
2
  import nltk
3
+ from nltk.tokenize import sent_tokenize
4
  import random
5
+ import requests
6
  import streamlit as st
7
  from langchain_openai import OpenAI
8
 
9
  # Download NLTK data (if not already downloaded)
10
  nltk.download('punkt')
11
+ nltk.download('averaged_perceptron_tagger')
12
 
13
+ # ChatGPT API endpoint
14
+ CHATGPT_API_ENDPOINT = "https://api.openai.com/v1/chat/completions"
15
+ OPENAI_API_KEY = "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"
16
 
17
  def extract_text_from_pdf(pdf_file):
18
  pdf_reader = PyPDF2.PdfReader(pdf_file)
 
37
  return mcqs
38
 
39
  def generate_question_with_chatgpt(context):
40
+
41
+
42
+ headers = {
43
+ "Content-Type": "application/json",
44
+ "Authorization": f"Bearer {OPENAI_API_KEY}",
45
+ }
46
+
47
  # Initializing the default value
48
  generated_question = {
49
  'content': "Unable to generate a question..",
 
61
  ],
62
  }
63
 
64
+ response = requests.post(CHATGPT_API_ENDPOINT, json=data, headers=headers)
65
  result = response.json()
66
 
67
  print("API Response:", result) # Add this line for debugging
 
78
 
79
  return generated_question
80
 
81
+
82
  def main():
83
  # Title of the Application
84
  st.header("🤖CB Quiz Generator🧠", divider='rainbow')