aaliyaan commited on
Commit
65dee87
·
1 Parent(s): b34d7e8

changes to interface

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -4,7 +4,7 @@ from PyPDF2 import PdfReader
4
 
5
  # Models Setup
6
  models = {
7
- "Text Generator (Zephyr)": {
8
  "client": InferenceClient(model="HuggingFaceH4/zephyr-7b-beta"),
9
  },
10
  "PDF Summarizer (T5)": {
@@ -22,7 +22,7 @@ def chat_with_model(model_choice, user_message, chat_history, file=None):
22
  user_message += f"\n\nPDF Content:\n{pdf_text}"
23
 
24
  if not user_message.strip():
25
- return chat_history
26
 
27
  model_info = models[model_choice]
28
  client = model_info["client"]
@@ -52,7 +52,7 @@ def chat_with_model(model_choice, user_message, chat_history, file=None):
52
 
53
  # Update Chat History
54
  chat_history.append((user_message, response))
55
- return chat_history
56
 
57
  # Function to Extract Text from PDF
58
  def extract_text_from_pdf(file):
@@ -82,14 +82,14 @@ def create_chat_interface():
82
  with gr.Row():
83
  model_choice = gr.Dropdown(
84
  choices=list(models.keys()),
85
- value="Text Generator (Zephyr)",
86
  label="Select Model"
87
  )
88
 
89
  chat_history = gr.Chatbot(label="Chat History", elem_classes="chatbox")
90
 
91
  user_message = gr.Textbox(
92
- placeholder="Type your message here...",
93
  show_label=False,
94
  elem_classes="chatbox",
95
  )
@@ -101,13 +101,11 @@ def create_chat_interface():
101
 
102
  model_choice.change(fn=toggle_pdf_input, inputs=model_choice, outputs=file_input)
103
 
104
- send_button = gr.Button("Send")
105
-
106
- # Link the send button to the chat function
107
- send_button.click(
108
  chat_with_model,
109
  inputs=[model_choice, user_message, chat_history, file_input],
110
- outputs=chat_history,
111
  )
112
 
113
  return interface
 
4
 
5
  # Models Setup
6
  models = {
7
+ "Job Consultant (Zephyr)": {
8
  "client": InferenceClient(model="HuggingFaceH4/zephyr-7b-beta"),
9
  },
10
  "PDF Summarizer (T5)": {
 
22
  user_message += f"\n\nPDF Content:\n{pdf_text}"
23
 
24
  if not user_message.strip():
25
+ return chat_history, ""
26
 
27
  model_info = models[model_choice]
28
  client = model_info["client"]
 
52
 
53
  # Update Chat History
54
  chat_history.append((user_message, response))
55
+ return chat_history, ""
56
 
57
  # Function to Extract Text from PDF
58
  def extract_text_from_pdf(file):
 
82
  with gr.Row():
83
  model_choice = gr.Dropdown(
84
  choices=list(models.keys()),
85
+ value="Job Consultant (Zephyr)",
86
  label="Select Model"
87
  )
88
 
89
  chat_history = gr.Chatbot(label="Chat History", elem_classes="chatbox")
90
 
91
  user_message = gr.Textbox(
92
+ placeholder="Type your message here and press Enter...",
93
  show_label=False,
94
  elem_classes="chatbox",
95
  )
 
101
 
102
  model_choice.change(fn=toggle_pdf_input, inputs=model_choice, outputs=file_input)
103
 
104
+ # Link the input box to send messages on Enter
105
+ user_message.submit(
 
 
106
  chat_with_model,
107
  inputs=[model_choice, user_message, chat_history, file_input],
108
+ outputs=[chat_history, user_message],
109
  )
110
 
111
  return interface