import streamlit as st
import parsing
from custom_prompt import TexRestructureTemplate,MetadataTemplate
import ast
from gpt import get_chat_completion
import openai
def main():
st.sidebar.markdown("""
""", unsafe_allow_html=True)
st.sidebar.image(image="physigen.png", width=100)
st.sidebar.title('Demo Links')
st.sidebar.markdown("[Link-1](https://www.shaalaa.com/question-bank-solutions/a-particle-mass-100-g-kept-surface-uniform-sphere-mass-10-kg-radius-10-cm-newton-s-universal-law-of-gravitation_66992#ref=chapter&id=53499)")
st.sidebar.markdown("[Link-2](https://www.shaalaa.com/question-bank-solutions/a-block-mass-2-kg-pushed-against-rough-vertical-wall-force-40-n-coefficient-static-friction-being-05-static-and-kinetic-friction_66797#ref=chapter&id=53300)")
st.sidebar.markdown("[Link-3](https://www.shaalaa.com/question-bank-solutions/the-average-separation-between-proton-electron-hydrogen-atom-ground-state-53-10-11-m-a-calculate-coulomb-force-between-them-this-separation-work-done-by-a-constant-force-and-a-variable-force_66339#ref=chapter&id=52831)")
st.sidebar.markdown("""
- MR PRADIPTA PATTANAYAK
- MR LIKHIT NAYAK
- MR ASHUTOS SAHOO
- SK SHAHID
""", unsafe_allow_html=True)
st.sidebar.markdown(
"""
© 2023 Physigen
""",unsafe_allow_html=True
)
st.title("JEE Main Physics Question Parser")
# Get the link input from the user
link = st.text_input("Enter the link to the JEE Main physics question:")
openAiKey = st.text_input(label="Input the openai key", type="password")
if st.button("Submit"):
if link:
try:
ques,ans = parsing.parse(link)
print("Checkpoint-1")
openai.api_key = openAiKey
restructure_prompt = TexRestructureTemplate()
q_restruct_prompt = restructure_prompt.format(content=ques)
question = get_chat_completion(q_restruct_prompt)
print(question)
print("Checkpoint-2")
meta_data_prompt = MetadataTemplate()
metadata_prompt = meta_data_prompt.format(answers=ans)
meta_data = get_chat_completion(metadata_prompt)
print(meta_data)
print("Checkpoint-3")
restructure_prompt = TexRestructureTemplate()
explanation_restruct_prompt = restructure_prompt.format(content=ans)
explanation = get_chat_completion(explanation_restruct_prompt)
# print(explanation)
# print("Checkpoint-4")
meta_data=ast.literal_eval(meta_data)
instruction=f'''Generate a {meta_data['metadata']["difficulty"]} difficulty physics question on the topic of {meta_data['metadata']["topic"]},subtopic {meta_data['metadata']["subtopic"]}, that tests {meta_data['metadata']["question_type"]} skills, and test the skills of {' and '.join(meta_data['metadata']["skills_tested"])}'''
answer=meta_data['answer']
metadata=meta_data['metadata']
# print(instruction)
# print("--"*20)
# print(question)
# print("--"*20)
# print(answer)
# print("--"*20)
# print(explanation)
# print("--"*20)
# print(metadata)
output_data = {
"instruction": instruction,
"question": question,
"answer": answer,
"explanation": explanation,
"metadata": metadata
}
# Display the combined data as JSON
st.subheader("Link Result")
st.json(output_data)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please enter a valid link.")
if __name__ == "__main__":
main()