faustocarrera commited on
Commit
c7033f4
·
verified ·
1 Parent(s): e5c4d56

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+
5
+ # Load your API key from environment (make sure it's set in the Hugging Face Secrets)
6
+ openai.api_key = os.environ.get("OPENAI_API_KEY")
7
+
8
+ # Optional: you can define this as a reusable variable if you plan to expand the prompt later
9
+ def generate_feedback(user_input):
10
+ try:
11
+ response = openai.ChatCompletion.create(
12
+ model="gpt-3.5-turbo", # Required for compatibility
13
+ messages=[
14
+ {"role": "system", "content": "You are a helpful writing coach."},
15
+ {"role": "user", "content": f"Here is a student’s answer: {user_input}\nGive 2–3 sentences of thoughtful, supportive feedback."}
16
+ ]
17
+ )
18
+ return response.choices[0].message['content']
19
+ except Exception as e:
20
+ print("Error during OpenAI call:", e)
21
+ return f"Error: {str(e)}"
22
+
23
+ # Build the UI
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("## ✍️ AI Feedback System\nEnter your writing below to receive helpful feedback.")
26
+ input_text = gr.Textbox(lines=10, label="Your Writing")
27
+ output_text = gr.Textbox(label="AI Feedback")
28
+ submit_btn = gr.Button("Get Feedback")
29
+
30
+ submit_btn.click(generate_feedback, inputs=input_text, outputs=output_text)
31
+
32
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==4.20.1
2
+ openai==0.28
3
+ python-dotenv==1.0.1
4
+ langchain==0.1.14
5
+ langchain-community==0.0.30