m-ric HF staff commited on
Commit
2a1c060
1 Parent(s): 3244268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -22,7 +22,7 @@ def extract_separators_from_string(separators_str):
22
  except Exception as e:
23
  raise gr.Error(f"""
24
  Did not succeed in extracting seperators from string: {separator_str} due to: {str(e)}.
25
- Please type it in the correct format: "['separator_1', 'separator_2', etc]"
26
  """)
27
 
28
  def change_split_selection(text, slider_count, split_selection, separator_selection, length_unit_selection, chunk_overlap):
@@ -60,21 +60,19 @@ def chunk(text, length, splitter_selection, separators_str, length_unit_selectio
60
  unoverlapped_text_splits = unoverlap_list(text_splits)
61
 
62
  output = [((split[0], 'Overlap') if split[1] else (split[0], f"Chunk {str(i)}")) for i, split in enumerate(unoverlapped_text_splits)]
63
- print(output)
64
  return output
65
 
66
 
67
- ESSAY = """### Chapter 6
68
 
69
  WHAT SORT OF DESPOTISM DEMOCRATIC NATIONS HAVE TO FEAR
70
 
71
  I had remarked during my stay in the United States that a democratic state of society, similar to that of the Americans, might offer singular facilities for the establishment of despotism; and I perceived, upon my return to Europe, how much use had already been made, by most of our rulers, of the notions, the sentiments, and the wants created by this same social condition, for the purpose of extending the circle of their power. This led me to think that the nations of Christendom would perhaps eventually undergo some oppression like that which hung over several of the nations of the ancient world.
72
  A more accurate examination of the subject, and five years of further meditation, have not diminished my fears, but have changed their object.
73
  No sovereign ever lived in former ages so absolute or so powerful as to undertake to administer by his own agency, and without the assistance of intermediate powers, all the parts of a great empire; none ever attempted to subject all his subjects indiscriminately to strict uniformity of regulation and personally to tutor and direct every member of the community. The notion of such an undertaking never occurred to the human mind; and if any man had conceived it, the want of information, the imperfection of the administrative system, and, above all, the natural obstacles caused by the inequality of conditions would speedily have checked the execution of so vast a design.
 
74
 
75
- ---
76
-
77
-
78
  ### Challenges of agent systems
79
 
80
  Generally, the difficult parts of running an agent system for the LLM engine are:
@@ -108,7 +106,7 @@ chat_model = ChatHuggingFace(llm=llm)
108
  ```
109
  """
110
 
111
-
112
  with gr.Blocks(theme=gr.themes.Soft(text_size='lg', font=["monospace"], primary_hue=gr.themes.colors.green)) as demo:
113
  text = gr.Textbox(label="Your text 🪶", value=ESSAY)
114
  with gr.Row():
@@ -127,6 +125,7 @@ with gr.Blocks(theme=gr.themes.Soft(text_size='lg', font=["monospace"], primary_
127
  show_label=False, # or set label to an empty string if you want to keep its space
128
  visible=False,
129
  )
 
130
  with gr.Row():
131
  length_unit_selection = gr.Dropdown(
132
  choices=[
 
22
  except Exception as e:
23
  raise gr.Error(f"""
24
  Did not succeed in extracting seperators from string: {separator_str} due to: {str(e)}.
25
+ Please type it in the correct format: "['separator_1', 'separator_2', ...]"
26
  """)
27
 
28
  def change_split_selection(text, slider_count, split_selection, separator_selection, length_unit_selection, chunk_overlap):
 
60
  unoverlapped_text_splits = unoverlap_list(text_splits)
61
 
62
  output = [((split[0], 'Overlap') if split[1] else (split[0], f"Chunk {str(i)}")) for i, split in enumerate(unoverlapped_text_splits)]
 
63
  return output
64
 
65
 
66
+ EXAMPLE_TEXT = """### Chapter 6
67
 
68
  WHAT SORT OF DESPOTISM DEMOCRATIC NATIONS HAVE TO FEAR
69
 
70
  I had remarked during my stay in the United States that a democratic state of society, similar to that of the Americans, might offer singular facilities for the establishment of despotism; and I perceived, upon my return to Europe, how much use had already been made, by most of our rulers, of the notions, the sentiments, and the wants created by this same social condition, for the purpose of extending the circle of their power. This led me to think that the nations of Christendom would perhaps eventually undergo some oppression like that which hung over several of the nations of the ancient world.
71
  A more accurate examination of the subject, and five years of further meditation, have not diminished my fears, but have changed their object.
72
  No sovereign ever lived in former ages so absolute or so powerful as to undertake to administer by his own agency, and without the assistance of intermediate powers, all the parts of a great empire; none ever attempted to subject all his subjects indiscriminately to strict uniformity of regulation and personally to tutor and direct every member of the community. The notion of such an undertaking never occurred to the human mind; and if any man had conceived it, the want of information, the imperfection of the administrative system, and, above all, the natural obstacles caused by the inequality of conditions would speedily have checked the execution of so vast a design.
73
+ """
74
 
75
+ EXAMPLE_MARKDOWN = """
 
 
76
  ### Challenges of agent systems
77
 
78
  Generally, the difficult parts of running an agent system for the LLM engine are:
 
106
  ```
107
  """
108
 
109
+
110
  with gr.Blocks(theme=gr.themes.Soft(text_size='lg', font=["monospace"], primary_hue=gr.themes.colors.green)) as demo:
111
  text = gr.Textbox(label="Your text 🪶", value=ESSAY)
112
  with gr.Row():
 
125
  show_label=False, # or set label to an empty string if you want to keep its space
126
  visible=False,
127
  )
128
+ preset_selection = gr.Radio(['Text', 'Code', 'Markdown'], label="Choose a preset", info="This will choose RecursiveCharacterTextSplitter with a specific set of separators.")
129
  with gr.Row():
130
  length_unit_selection = gr.Dropdown(
131
  choices=[