AamirAli123 commited on
Commit
ee33ea8
1 Parent(s): 820635d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -34,18 +34,18 @@ def analyze_feedback(feedback_text):
34
  )
35
  return chat_completion.choices[0].message.content
36
 
37
- def process_files(uploaded_files):
38
  results = [["File Name", "Summary", "Areas of Improvement", "Actionable Objectives","Sentiment", "Themes"]]
39
-
40
- for file_path in uploaded_files:
41
- # Extract file name from the file path
42
- file_name = os.path.basename(file_path)
43
-
44
- # Open and read the file content
45
- with open(file_path, 'r', encoding='utf-8') as file:
46
- feedback_text = file.read()
47
- #print(feedback_text)
48
-
49
  # Process the feedback text
50
  processed_feedback = process_feedback(feedback_text)
51
 
@@ -107,7 +107,7 @@ def process_feedback(feedback_text):
107
 
108
  return analysis_results
109
 
110
- def display_results(uploaded_files):
111
  """
112
  Processes uploaded feedback files and displays the results.
113
 
@@ -117,7 +117,7 @@ def display_results(uploaded_files):
117
  Returns:
118
  tuple: A tuple containing various analysis results or an empty string if no files were uploaded.
119
  """
120
- feedback, results = process_files(uploaded_files)
121
  if results:
122
  # Extract each area of feedback from the dictionary
123
  summary = results['summary'] if 'summary' in results else ""
@@ -192,13 +192,14 @@ custom_css = """
192
  with gr.Blocks(gr.themes.Monochrome(), css=custom_css) as demo:
193
  # Display introductory markdown content
194
  gr.Markdown(f"""<center>{markdown_content}</center>
195
- <p>**NOTE**: Below some txt file examples given. Makesure to upload the content should be as given below.</p>
196
  """)
197
  # Layout elements in a row
198
  with gr.Column():
199
-
200
- # Upload button for selecting files
201
- upload_button = gr.File(file_types=[".txt"], file_count="multiple")
 
202
  # Button to trigger analysis
203
  submit_button = gr.Button("Submit")
204
 
@@ -239,7 +240,7 @@ with gr.Blocks(gr.themes.Monochrome(), css=custom_css) as demo:
239
  # Connect button click to analysis function
240
  submit_button.click(
241
  display_results,
242
- inputs = [upload_button],
243
  outputs = [
244
  output_summary,
245
  output_themes,
 
34
  )
35
  return chat_completion.choices[0].message.content
36
 
37
+ def process_files(uploaded_files, text_data):
38
  results = [["File Name", "Summary", "Areas of Improvement", "Actionable Objectives","Sentiment", "Themes"]]
39
+ if text_data == "":
40
+ for file_path in uploaded_files:
41
+ # Extract file name from the file path
42
+ file_name = os.path.basename(file_path)
43
+ # Open and read the file content
44
+ with open(file_path, 'r', encoding='utf-8') as file:
45
+ feedback_text = file.read()
46
+ #print(feedback_text)
47
+ else:
48
+ feedback_text = text_data
49
  # Process the feedback text
50
  processed_feedback = process_feedback(feedback_text)
51
 
 
107
 
108
  return analysis_results
109
 
110
+ def display_results(uploaded_files, text_data):
111
  """
112
  Processes uploaded feedback files and displays the results.
113
 
 
117
  Returns:
118
  tuple: A tuple containing various analysis results or an empty string if no files were uploaded.
119
  """
120
+ feedback, results = process_files(uploaded_files, text_data)
121
  if results:
122
  # Extract each area of feedback from the dictionary
123
  summary = results['summary'] if 'summary' in results else ""
 
192
  with gr.Blocks(gr.themes.Monochrome(), css=custom_css) as demo:
193
  # Display introductory markdown content
194
  gr.Markdown(f"""<center>{markdown_content}</center>
195
+ <p>**NOTE**: Below some txt examples given. Makesure to uploaded file content OR input text should be as given below.</p>
196
  """)
197
  # Layout elements in a row
198
  with gr.Column():
199
+ with gr.Row():
200
+ # Upload button for selecting files
201
+ upload_button = gr.File(file_types=[".txt"], file_count = "multiple")
202
+ upload_text = gr.TextArea(placeholder = "enter your text here")
203
  # Button to trigger analysis
204
  submit_button = gr.Button("Submit")
205
 
 
240
  # Connect button click to analysis function
241
  submit_button.click(
242
  display_results,
243
+ inputs = [upload_button, upload_text],
244
  outputs = [
245
  output_summary,
246
  output_themes,