Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,30 +9,39 @@ from langchain.chains import LLMChain
|
|
| 9 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 10 |
|
| 11 |
# Prompt Template
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
template="""You are a writing coach who gives {tone} feedback.
|
| 15 |
-
Here
|
| 16 |
-
|
| 17 |
"""
|
| 18 |
)
|
| 19 |
|
|
|
|
| 20 |
# Update these imports to use the new recommended packages
|
| 21 |
from langchain_community.chat_models import ChatOpenAI # or from langchain_openai import ChatOpenAI
|
| 22 |
|
| 23 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.7)
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
})
|
| 32 |
except Exception as e:
|
| 33 |
-
print("Error during Langchain call:", e)
|
| 34 |
return f"Error: {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
| 36 |
# Build the UI
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
gr.Markdown("#0 AI Feedback System\nChoose a tone and get feedback on your writing.")
|
|
|
|
| 9 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 10 |
|
| 11 |
# Prompt Template
|
| 12 |
+
# Prompt template
|
| 13 |
+
summarize_Prompt = PromptTemplate(
|
| 14 |
+
input_variables=["student_input"],
|
| 15 |
+
template="Summarize the following writing:\\n{student_input}"
|
| 16 |
+
)
|
| 17 |
+
feedback_prompt = PromptTemplate(
|
| 18 |
+
input_variables=["summary", "tone"],
|
| 19 |
template="""You are a writing coach who gives {tone} feedback.
|
| 20 |
+
Here's a summary of a student's writing: {summary}
|
| 21 |
+
Give 2-3 sentences of constructive suggestions to improve the writing.
|
| 22 |
"""
|
| 23 |
)
|
| 24 |
|
| 25 |
+
|
| 26 |
# Update these imports to use the new recommended packages
|
| 27 |
from langchain_community.chat_models import ChatOpenAI # or from langchain_openai import ChatOpenAI
|
| 28 |
|
| 29 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0.7)
|
| 30 |
+
summarize_chain = LLMChain(llm=llm, prompt=summarize_Prompt)
|
| 31 |
+
feedback_chain = LLMChain(llm=llm, prompt=feedback_prompt)
|
| 32 |
|
| 33 |
+
|
| 34 |
+
# Feedback function using langChain
|
| 35 |
+
def generate_feedback(student_input, tone='supportive'):
|
| 36 |
try:
|
| 37 |
+
summary = summarize_chain.run({'student_input': student_input})
|
| 38 |
+
final_feedback = feedback_chain.run({'summary': summary, 'tone': tone})
|
| 39 |
+
return final_feedback
|
|
|
|
| 40 |
except Exception as e:
|
|
|
|
| 41 |
return f"Error: {str(e)}"
|
| 42 |
|
| 43 |
+
|
| 44 |
+
|
| 45 |
# Build the UI
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
gr.Markdown("#0 AI Feedback System\nChoose a tone and get feedback on your writing.")
|