Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,18 +6,36 @@ from PIL import Image
|
|
| 6 |
import io
|
| 7 |
from langchain_community.document_loaders import YoutubeLoader
|
| 8 |
import pyttsx3
|
| 9 |
-
|
| 10 |
# Initialize OpenAI API
|
| 11 |
-
openai.api_key = 'sk-proj-
|
| 12 |
|
| 13 |
# Function to generate content using ChatGPT
|
| 14 |
def generate_content(messages):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def summarize_youtube_video(video_url, openai_api_key, max_tokens=1500):
|
| 23 |
openai.api_key = openai_api_key
|
|
@@ -67,18 +85,13 @@ def summarize_youtube_video(video_url, openai_api_key, max_tokens=1500):
|
|
| 67 |
{transcript_text}
|
| 68 |
"""
|
| 69 |
|
| 70 |
-
# Use
|
| 71 |
messages = [
|
| 72 |
{"role": "system", "content": "You are a helpful teaching assistant."},
|
| 73 |
{"role": "user", "content": prompt}
|
| 74 |
]
|
| 75 |
-
response = openai.ChatCompletion.create(
|
| 76 |
-
model="gpt-4",
|
| 77 |
-
messages=messages,
|
| 78 |
-
max_tokens=max_tokens,
|
| 79 |
-
)
|
| 80 |
-
summary = response.choices[0].message['content'].strip()
|
| 81 |
|
|
|
|
| 82 |
return summary
|
| 83 |
|
| 84 |
# Function to create a PDF
|
|
@@ -130,7 +143,7 @@ st.title("Teaching Assistant Application")
|
|
| 130 |
st.sidebar.header("Options")
|
| 131 |
option = st.sidebar.selectbox(
|
| 132 |
"Choose an option",
|
| 133 |
-
["Generate Test Questions","Youtube Video Summeriser","Generate Project Based Learning", "Create Course Curriculum", "Create Assignments", "Create Activities"
|
| 134 |
)
|
| 135 |
|
| 136 |
st.header(option)
|
|
@@ -179,7 +192,15 @@ if option == "Generate Test Questions":
|
|
| 179 |
st.subheader("Generated Content")
|
| 180 |
st.write(content)
|
| 181 |
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
else:
|
| 184 |
st.warning("Please enter both a topic and a standard.")
|
| 185 |
|
|
@@ -190,12 +211,20 @@ if option == "Youtube Video Summeriser" :
|
|
| 190 |
if st.button("Summarize Video"):
|
| 191 |
if video_url:
|
| 192 |
|
| 193 |
-
content = summarize_youtube_video(video_url, 'sk-proj-
|
| 194 |
st.subheader("Generated Report")
|
| 195 |
st.session_state.summary = content
|
| 196 |
st.markdown(content)
|
| 197 |
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
if option == "Generate Project Based Learning":
|
| 201 |
topic = st.text_input("Enter the topic")
|
|
@@ -243,7 +272,16 @@ Be creative, innovative, and engage deeply with the subject matter to make the m
|
|
| 243 |
st.subheader("Generated Content")
|
| 244 |
st.write(content)
|
| 245 |
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
else:
|
| 248 |
st.warning("Please enter both a topic and a standard.")
|
| 249 |
|
|
@@ -286,7 +324,16 @@ elif option == "Create Course Curriculum":
|
|
| 286 |
st.subheader("Generated Content")
|
| 287 |
st.write(content)
|
| 288 |
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
else:
|
| 291 |
st.warning("Please enter the subject(s).")
|
| 292 |
|
|
@@ -323,7 +370,16 @@ elif option == "Create Assignments":
|
|
| 323 |
st.subheader("Generated Content")
|
| 324 |
st.write(content)
|
| 325 |
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
else:
|
| 328 |
st.warning("Please enter the topic/keywords/goal.")
|
| 329 |
|
|
@@ -360,7 +416,16 @@ elif option == "Create Activities":
|
|
| 360 |
st.subheader("Generated Content")
|
| 361 |
st.write(content)
|
| 362 |
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
else:
|
| 365 |
st.warning("Please enter the topic/keywords.")
|
| 366 |
|
|
@@ -391,4 +456,13 @@ elif option == "Describe and Discuss Image":
|
|
| 391 |
st.subheader("Generated Content")
|
| 392 |
st.write(content)
|
| 393 |
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import io
|
| 7 |
from langchain_community.document_loaders import YoutubeLoader
|
| 8 |
import pyttsx3
|
| 9 |
+
import requests
|
| 10 |
# Initialize OpenAI API
|
| 11 |
+
openai.api_key = 'sk-proj-vwPU5Rhnd9FE5KO25fNdT3BlbkFJVrEvfXZ9YxxsO5lYzLw3'
|
| 12 |
|
| 13 |
# Function to generate content using ChatGPT
|
| 14 |
def generate_content(messages):
|
| 15 |
+
endpoint = 'https://api.together.xyz/v1/chat/completions'
|
| 16 |
+
headers = {
|
| 17 |
+
"Authorization": "Bearer dc073523ec85f07124dd84b16504a472905c1fac5542f3bf43f9043b8162afc7",
|
| 18 |
+
"Content-Type": "application/json"
|
| 19 |
+
}
|
| 20 |
+
data = {
|
| 21 |
+
"model": "meta-llama/Llama-3-8b-chat-hf",
|
| 22 |
+
"max_tokens": 1024,
|
| 23 |
+
"temperature": 0.7,
|
| 24 |
+
"top_p": 0.7,
|
| 25 |
+
"top_k": 50,
|
| 26 |
+
"repetition_penalty": 1,
|
| 27 |
+
"stop": ["<|eot_id|>"],
|
| 28 |
+
"messages": messages
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
response = requests.post(endpoint, headers=headers, json=data)
|
| 32 |
+
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
generated_text = response.json()['choices'][0]['message']['content']
|
| 35 |
+
return generated_text
|
| 36 |
+
else:
|
| 37 |
+
print(f"Error: {response.status_code} - {response.text}")
|
| 38 |
+
return "Error generating content"
|
| 39 |
|
| 40 |
def summarize_youtube_video(video_url, openai_api_key, max_tokens=1500):
|
| 41 |
openai.api_key = openai_api_key
|
|
|
|
| 85 |
{transcript_text}
|
| 86 |
"""
|
| 87 |
|
| 88 |
+
# Use gpt-3.5-turbo to summarize the transcript
|
| 89 |
messages = [
|
| 90 |
{"role": "system", "content": "You are a helpful teaching assistant."},
|
| 91 |
{"role": "user", "content": prompt}
|
| 92 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
summary = generate_content(messages)
|
| 95 |
return summary
|
| 96 |
|
| 97 |
# Function to create a PDF
|
|
|
|
| 143 |
st.sidebar.header("Options")
|
| 144 |
option = st.sidebar.selectbox(
|
| 145 |
"Choose an option",
|
| 146 |
+
["Generate Test Questions","Youtube Video Summeriser","Generate Project Based Learning", "Create Course Curriculum", "Create Assignments", "Create Activities"]
|
| 147 |
)
|
| 148 |
|
| 149 |
st.header(option)
|
|
|
|
| 192 |
st.subheader("Generated Content")
|
| 193 |
st.write(content)
|
| 194 |
|
| 195 |
+
if st.button("Export to PDF"):
|
| 196 |
+
pdf_path = "generated_content.pdf"
|
| 197 |
+
pdf_data = create_pdf(content, pdf_path)
|
| 198 |
+
st.download_button(
|
| 199 |
+
label="Download PDF",
|
| 200 |
+
data=pdf_data.getvalue(),
|
| 201 |
+
file_name="generated_content.pdf",
|
| 202 |
+
mime="application/pdf"
|
| 203 |
+
)
|
| 204 |
else:
|
| 205 |
st.warning("Please enter both a topic and a standard.")
|
| 206 |
|
|
|
|
| 211 |
if st.button("Summarize Video"):
|
| 212 |
if video_url:
|
| 213 |
|
| 214 |
+
content = summarize_youtube_video(video_url, 'sk-proj-vwPU5Rhnd9FE5KO25fNdT3BlbkFJVrEvfXZ9YxxsO5lYzLw3')
|
| 215 |
st.subheader("Generated Report")
|
| 216 |
st.session_state.summary = content
|
| 217 |
st.markdown(content)
|
| 218 |
|
| 219 |
+
if st.button("Export to PDF"):
|
| 220 |
+
pdf_path = "generated_content.pdf"
|
| 221 |
+
pdf_data = create_pdf(content, pdf_path)
|
| 222 |
+
st.download_button(
|
| 223 |
+
label="Download PDF",
|
| 224 |
+
data=pdf_data.getvalue(),
|
| 225 |
+
file_name="generated_content.pdf",
|
| 226 |
+
mime="application/pdf"
|
| 227 |
+
)
|
| 228 |
|
| 229 |
if option == "Generate Project Based Learning":
|
| 230 |
topic = st.text_input("Enter the topic")
|
|
|
|
| 272 |
st.subheader("Generated Content")
|
| 273 |
st.write(content)
|
| 274 |
|
| 275 |
+
if st.button("Export to PDF"):
|
| 276 |
+
pdf_path = os.path.join("generated_content.pdf")
|
| 277 |
+
create_pdf(content, pdf_path)
|
| 278 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 279 |
+
st.download_button(
|
| 280 |
+
label="Download PDF",
|
| 281 |
+
data=pdf_file,
|
| 282 |
+
file_name="generated_content.pdf",
|
| 283 |
+
mime="application/pdf"
|
| 284 |
+
)
|
| 285 |
else:
|
| 286 |
st.warning("Please enter both a topic and a standard.")
|
| 287 |
|
|
|
|
| 324 |
st.subheader("Generated Content")
|
| 325 |
st.write(content)
|
| 326 |
|
| 327 |
+
if st.button("Export to PDF"):
|
| 328 |
+
pdf_path = os.path.join("generated_content.pdf")
|
| 329 |
+
create_pdf(content, pdf_path)
|
| 330 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 331 |
+
st.download_button(
|
| 332 |
+
label="Download PDF",
|
| 333 |
+
data=pdf_file,
|
| 334 |
+
file_name="generated_content.pdf",
|
| 335 |
+
mime="application/pdf"
|
| 336 |
+
)
|
| 337 |
else:
|
| 338 |
st.warning("Please enter the subject(s).")
|
| 339 |
|
|
|
|
| 370 |
st.subheader("Generated Content")
|
| 371 |
st.write(content)
|
| 372 |
|
| 373 |
+
if st.button("Export to PDF"):
|
| 374 |
+
pdf_path = os.path.join("generated_content.pdf")
|
| 375 |
+
create_pdf(content, pdf_path)
|
| 376 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 377 |
+
st.download_button(
|
| 378 |
+
label="Download PDF",
|
| 379 |
+
data=pdf_file,
|
| 380 |
+
file_name="generated_content.pdf",
|
| 381 |
+
mime="application/pdf"
|
| 382 |
+
)
|
| 383 |
else:
|
| 384 |
st.warning("Please enter the topic/keywords/goal.")
|
| 385 |
|
|
|
|
| 416 |
st.subheader("Generated Content")
|
| 417 |
st.write(content)
|
| 418 |
|
| 419 |
+
if st.button("Export to PDF"):
|
| 420 |
+
pdf_path = os.path.join("generated_content.pdf")
|
| 421 |
+
create_pdf(content, pdf_path)
|
| 422 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 423 |
+
st.download_button(
|
| 424 |
+
label="Download PDF",
|
| 425 |
+
data=pdf_file,
|
| 426 |
+
file_name="generated_content.pdf",
|
| 427 |
+
mime="application/pdf"
|
| 428 |
+
)
|
| 429 |
else:
|
| 430 |
st.warning("Please enter the topic/keywords.")
|
| 431 |
|
|
|
|
| 456 |
st.subheader("Generated Content")
|
| 457 |
st.write(content)
|
| 458 |
|
| 459 |
+
if st.button("Export to PDF"):
|
| 460 |
+
pdf_path = os.path.join("generated_content.pdf")
|
| 461 |
+
create_pdf(content, pdf_path)
|
| 462 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 463 |
+
st.download_button(
|
| 464 |
+
label="Download PDF",
|
| 465 |
+
data=pdf_file,
|
| 466 |
+
file_name="generated_content.pdf",
|
| 467 |
+
mime="application/pdf"
|
| 468 |
+
)
|