Jasur05 commited on
Commit
6d5d19a
Β·
verified Β·
1 Parent(s): 310c862

go back to just one time chat

Browse files
Files changed (1) hide show
  1. app.py +35 -36
app.py CHANGED
@@ -106,42 +106,41 @@ def rag_answer(question: str, collection) -> str:
106
  return generate_agent_answer(context, question)
107
 
108
  # gradio interface code below
109
-
110
- def answer_question(user_input, history):
111
- answer = rag_answer(user_input, collection)
112
- history.append({"role": "user", "content": user_input})
113
- history.append({"role": "assistant", "content": answer})
114
- return "", history
115
-
116
-
117
- with gr.Blocks(title="πŸ“š Inha University SGCS Info Assistant") as demo:
118
- gr.Markdown("## πŸ“š Inha University SGCS Info Assistant")
119
- gr.Markdown("Get answers to your questions about Inha University SGCS.")
120
-
121
- chatbot = gr.Chatbot(label="πŸ“Œ Answer", type="messages") # βœ… Fixed type
122
-
123
- with gr.Row():
124
- textbox = gr.Textbox(
125
- placeholder="e.g. How many Major Required credits should I take for graduation?",
126
- label="Ask me anything about Inha University SGCS...",
127
- lines=2
128
- )
129
- send_btn = gr.Button("Send")
130
-
131
- history = gr.State([])
132
-
133
- send_btn.click(fn=answer_question, inputs=[textbox, history], outputs=[textbox, chatbot])
134
- textbox.submit(fn=answer_question, inputs=[textbox, history], outputs=[textbox, chatbot])
135
-
136
- gr.Examples(
137
- examples=[
138
- "What classes should I normally take as 3rd semester ISE student?",
139
- "Tell me about student organizations and activities",
140
- "What percentage scholarship could I receive with IELTS 7.0"
141
- ],
142
- inputs=textbox
143
- )
144
-
145
 
146
 
147
 
 
106
  return generate_agent_answer(context, question)
107
 
108
  # gradio interface code below
109
+ def answer_question(question):
110
+ """
111
+ Main function that processes the question and returns the answer
112
+ """
113
+ if not question.strip():
114
+ return "Please enter a question about Inha University."
115
+
116
+ try:
117
+ answer = rag_answer(question, collection)
118
+ return answer
119
+ except Exception as e:
120
+ return f"Sorry, I encountered an error: {str(e)}"
121
+
122
+ # ─── 6. Gradio Frontend ─────────────────────────────────────────────────────
123
+ # Create the Gradio interface
124
+ demo = gr.Interface(
125
+ fn=answer_question,
126
+ inputs=gr.Textbox(
127
+ label="Ask me anything about Inha University SGCS…",
128
+ placeholder="e.g. How many Major Required credits should I take for graduation? ",
129
+ lines=2
130
+ ),
131
+ outputs=gr.Markdown(
132
+ label="πŸ“Œ Answer",
133
+ show_copy_button=True
134
+ ),
135
+ title="πŸ“š Inha University SGCS Info Assistant",
136
+ description="Get answers to your questions about Inha University SGCS .",
137
+ theme=gr.themes.Soft(),
138
+ examples=[
139
+ ["What classes should I normally take as 3nd semester ISE student?"],
140
+ ["Tell me about student organizations and activities"],
141
+ ["What percentage scholarship could I recieve with IELTS 7.0"]
142
+ ]
143
+ )
 
144
 
145
 
146