mohammed3536 commited on
Commit
03110c9
1 Parent(s): bb0771d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -2,7 +2,6 @@ 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
 
@@ -10,9 +9,8 @@ from langchain_openai import OpenAI
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,13 +35,6 @@ def generate_mcqs_on_topic(text, topic, num_mcqs=5):
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..",
@@ -59,7 +50,7 @@ def generate_question_with_chatgpt(context):
59
  ],
60
  }
61
 
62
- response = requests.post(CHATGPT_API_ENDPOINT, json=data, headers=headers)
63
  result = response.json()
64
 
65
  print("API Response:", result) # Add this line for debugging
@@ -105,6 +96,7 @@ def main():
105
  if __name__ == "__main__":
106
  main()
107
 
 
108
 
109
 
110
 
 
2
  import nltk
3
  from nltk.tokenize import sent_tokenize
4
  import random
 
5
  import streamlit as st
6
  from langchain_openai import OpenAI
7
 
 
9
  nltk.download('punkt')
10
  nltk.download('averaged_perceptron_tagger')
11
 
12
+ # LangChain OpenAI wrapper
13
+ openai = OpenAI(api_key="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")
 
14
 
15
  def extract_text_from_pdf(pdf_file):
16
  pdf_reader = PyPDF2.PdfReader(pdf_file)
 
35
  return mcqs
36
 
37
  def generate_question_with_chatgpt(context):
 
 
 
 
 
 
 
38
  # Initializing the default value
39
  generated_question = {
40
  'content': "Unable to generate a question..",
 
50
  ],
51
  }
52
 
53
+ response = openai.complete(data)
54
  result = response.json()
55
 
56
  print("API Response:", result) # Add this line for debugging
 
96
  if __name__ == "__main__":
97
  main()
98
 
99
+
100
 
101
 
102