JishnuSetia commited on
Commit
6596717
·
verified ·
1 Parent(s): ac8fdcf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import InferenceClient
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ # Load .env file
7
+ load_dotenv()
8
+
9
+ # Get API key from environment variable
10
+ api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
11
+
12
+ st.set_page_config(page_title="EssayEase AI Chat", page_icon="🤖")
13
+
14
+ # Add system prompt once at the start
15
+ system_prompt = {
16
+ "role": "system",
17
+ "content": (
18
+ "You are EssayEASE, an intelligent and empathetic AI assistant designed to help students write compelling, "
19
+ "authentic, and well-structured college essays — including personal statements, supplemental essays, and scholarship responses. "
20
+ "You guide students in expressing their unique stories, values, and aspirations in a clear, reflective, and engaging manner.\n\n"
21
+ "⚠️ Important: You do not encourage plagiarism or AI-generated content to be submitted without proper editing. "
22
+ "All suggestions must serve as guidance or inspiration. Students should ensure the final work is entirely their own voice and experience.\n\n"
23
+ "Your tone should be supportive, thoughtful, and motivational. Offer constructive feedback, ask reflective questions, and give helpful examples. "
24
+ "Maintain the student's original voice and ensure your responses help them grow as a writer."
25
+ )
26
+ }
27
+
28
+ # Initialize chat history
29
+ if "messages" not in st.session_state:
30
+ st.session_state.messages = []
31
+
32
+ # Title
33
+ st.title("🧠 EssayEase — AI Essay Helper")
34
+
35
+ # User input
36
+ user_input = st.chat_input("Draft or ask anything essay-related...")
37
+
38
+ # Show past messages
39
+ for msg in st.session_state.messages:
40
+ with st.chat_message(msg["role"]):
41
+ st.markdown(msg["content"])
42
+
43
+ # If new input
44
+ if user_input:
45
+ st.session_state.messages.append({"role": "user", "content": user_input})
46
+
47
+ with st.chat_message("user"):
48
+ st.markdown(user_input)
49
+
50
+ with st.chat_message("assistant"):
51
+ with st.spinner("Thinking..."):
52
+ try:
53
+ client = InferenceClient(
54
+ model="nvidia/Llama-3_1-Nemotron-Ultra-253B-v1",
55
+ provider="nebius",
56
+ api_key=api_key,
57
+ )
58
+
59
+ # Add system prompt only once at the start of the context
60
+ full_context = [system_prompt] + st.session_state.messages
61
+
62
+ completion = client.chat.completions.create(
63
+ model="nvidia/Llama-3_1-Nemotron-Ultra-253B-v1",
64
+ messages=full_context,
65
+ max_tokens=2048,
66
+ )
67
+
68
+ response = completion.choices[0].message.content
69
+
70
+ except Exception as e:
71
+ response = f"❌ Error: {e}"
72
+
73
+ st.markdown(response)
74
+ st.session_state.messages.append({"role": "assistant", "content": response})