|
import streamlit as st |
|
import requests |
|
|
|
|
|
session = requests.Session() |
|
|
|
|
|
def chat_with_ai(message): |
|
api_url = "https://free-ai-api.devastation-war.repl.co/chat" |
|
payload = {"message": message} |
|
|
|
try: |
|
with session.post(api_url, json=payload) as response: |
|
if response.status_code == 200: |
|
return response.json().get('response') |
|
else: |
|
return {"error": "Failed to get a response from the AI API."} |
|
except requests.RequestException as e: |
|
return {"error": f"Error: {e}"} |
|
|
|
|
|
def main(): |
|
st.title("Generate Study Notes") |
|
|
|
|
|
user_class = st.sidebar.selectbox('Select your class:', ['Class 1', 'Class 2', 'Class 3', 'Class 4', 'Class 5', 'Class 6', |
|
'Class 7', 'Class 8', 'Class 9', 'Class 10', 'Class 11', 'Class 12']) |
|
user_input = st.text_input(f'Enter your study topic for {user_class}:', placeholder='e.g., History') |
|
|
|
|
|
if st.button('Generate Study Notes'): |
|
if user_input.lower() in ['quit', 'exit', 'bye']: |
|
st.success("Goodbye! Have a great day!") |
|
else: |
|
with st.spinner("Generating study notes. Please wait..."): |
|
prompt = f"Provide study notes for {user_class} on the topic: {user_input}." |
|
response = chat_with_ai(prompt) |
|
|
|
|
|
st.subheader(f"Study Notes for {user_class} - {user_input}") |
|
st.write(response) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|