Ninjasharp commited on
Commit
2c339f3
·
verified ·
1 Parent(s): c2e13da

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -28
app.py CHANGED
@@ -28,7 +28,7 @@ if not groq_api_key:
28
  st.stop()
29
 
30
  client = Groq(api_key=groq_api_key)
31
- st.image("p1.png", width=200)
32
  st.sidebar.image("p2.png", width=200)
33
 
34
  def main():
@@ -40,30 +40,26 @@ def main():
40
  temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.5)
41
  output_size = st.sidebar.selectbox(
42
  "Select Output Size",
43
- [
44
- "2-5 word sentences",
45
- "3-7 word sentences",
46
- "5-9 word sentences",
47
- "6-11 word sentences"
48
- ]
49
  )
50
  bullet_points = st.sidebar.checkbox("Output as Bullet Points")
51
  humanize_text = st.sidebar.checkbox("Humanize Text")
52
-
 
 
53
  # Clear and reset buttons in the sidebar
54
  if st.sidebar.button("Clear Input Fields"):
55
- st.session_state.system_prompt = "Create a revised [text] concise and focused, Provide the output in bullet points or a brief paragraph, offer 2-3 alternates - suggest areas for improvement. . list final answer in separate area"
56
  st.session_state.user_query = ""
57
 
58
-
59
  # Input fields for system prompt and query
60
- default_prompt = "Create a revised [text] concise and focused, Provide the output in bullet points or a brief paragraph, offer 2-3 alternates - suggest areas for improvement. . list final answer in separate area"
61
  system_prompt = st.text_area("System Prompt", value=st.session_state.get("system_prompt", default_prompt), key="system_prompt")
62
  user_query = st.text_area("Enter Your Query", value=st.session_state.get("user_query", ""), key="user_query")
63
 
64
  if st.button("Submit"):
65
  with st.spinner("Generating response..."):
66
- response = query_groq(model, temperature, system_prompt, user_query, output_size, humanize_text)
67
 
68
  col1, col2 = st.columns(2)
69
 
@@ -75,23 +71,25 @@ def main():
75
  "Output Size": output_size,
76
  "Bullet Points": bullet_points,
77
  "Humanize Text": humanize_text,
 
78
  "System Prompt": system_prompt,
79
  "User Query": user_query
80
  })
 
 
 
81
 
82
  with col2:
83
- st.write("### Output Response")
84
- st.text(response)
85
-
86
- st.write("### Processed Response")
87
- if response.startswith("Error:"):
88
- st.error(response)
89
- else:
90
- processed_response = process_response(response, output_size, bullet_points, humanize_text)
91
- st.write("**Generated Response:**")
92
- st.text_area("Processed Response", value=processed_response, height=200, disabled=True)
93
 
94
- def query_groq(model, temperature, system_prompt, user_query, output_size, humanize_text):
95
  try:
96
  completion = client.chat.completions.create(
97
  model=SUPPORTED_MODELS[model],
@@ -108,8 +106,15 @@ def query_groq(model, temperature, system_prompt, user_query, output_size, human
108
  except Exception as e:
109
  return f"Error: {str(e)}"
110
 
111
- def process_response(text, output_size, bullet_points, humanize_text):
112
- if output_size == "2-5 word sentences":
 
 
 
 
 
 
 
113
  text = reduce_to_sentences(text, 2, 5)
114
  elif output_size == "3-7 word sentences":
115
  text = reduce_to_sentences(text, 3, 7)
@@ -119,7 +124,7 @@ def process_response(text, output_size, bullet_points, humanize_text):
119
  text = reduce_to_sentences(text, 6, 11)
120
 
121
  if bullet_points:
122
- text = reduce_to_bullet_points(text, 2, 11) # Adjusting min and max word count for bullet points
123
 
124
  if humanize_text:
125
  text = humanize(text)
@@ -145,10 +150,10 @@ def reduce_to_sentences(text, min_words, max_words):
145
  return ' '.join(filtered_sentences)
146
 
147
  def humanize(text):
148
- # TODO: Implement a more sophisticated humanization function
149
  return text.replace(". ", ". Let's consider this further. ")
150
 
151
  st.sidebar.info("build by dw")
152
 
153
  if __name__ == "__main__":
154
- main()
 
28
  st.stop()
29
 
30
  client = Groq(api_key=groq_api_key)
31
+ st.image("p1.png", width=300)
32
  st.sidebar.image("p2.png", width=200)
33
 
34
  def main():
 
40
  temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.5)
41
  output_size = st.sidebar.selectbox(
42
  "Select Output Size",
43
+ ["1-3 word sentences", "2-5 word sentences", "3-7 word sentences", "5-9 word sentences", "6-11 word sentences"]
 
 
 
 
 
44
  )
45
  bullet_points = st.sidebar.checkbox("Output as Bullet Points")
46
  humanize_text = st.sidebar.checkbox("Humanize Text")
47
+ display_final_answer = st.sidebar.checkbox("Display Process")
48
+ reduce_words = st.sidebar.checkbox("Reduce Word Count by 50%") # New checkbox for reducing word count
49
+
50
  # Clear and reset buttons in the sidebar
51
  if st.sidebar.button("Clear Input Fields"):
52
+ st.session_state.system_prompt = "Create a revised [text] use 3-5 words concise and focused, Provide the output in short format plus in bullet points or a brief paragraph, plus offer 2-3 alternates - suggest areas for improvement. . list final answer in separate area"
53
  st.session_state.user_query = ""
54
 
 
55
  # Input fields for system prompt and query
56
+ default_prompt = "Create a revised [text] use 3-5 words concise and focused, Provide the output in short format plus in bullet points or a brief paragraph, plus offer 2-3 alternates - suggest areas for improvement. . list final answer in separate area"
57
  system_prompt = st.text_area("System Prompt", value=st.session_state.get("system_prompt", default_prompt), key="system_prompt")
58
  user_query = st.text_area("Enter Your Query", value=st.session_state.get("user_query", ""), key="user_query")
59
 
60
  if st.button("Submit"):
61
  with st.spinner("Generating response..."):
62
+ response = query_groq(model, temperature, system_prompt, user_query, output_size, humanize_text, reduce_words)
63
 
64
  col1, col2 = st.columns(2)
65
 
 
71
  "Output Size": output_size,
72
  "Bullet Points": bullet_points,
73
  "Humanize Text": humanize_text,
74
+ "Display Final Answer": display_final_answer,
75
  "System Prompt": system_prompt,
76
  "User Query": user_query
77
  })
78
+ if display_final_answer:
79
+ st.write("### Original Response")
80
+ st.text_area("Original Response", value=response, height=400)
81
 
82
  with col2:
83
+ if display_final_answer:
84
+ processed_response = process_response(response, output_size, bullet_points, humanize_text, reduce_words)
85
+ additional_text = "Please review the response carefully before proceeding."
86
+ st.write("### Processed Response with Review")
87
+ st.text_area(response, value=processed_response + "\n" + additional_text, height=200)
88
+ else:
89
+ st.write("### Output Response")
90
+ st.text(response)
 
 
91
 
92
+ def query_groq(model, temperature, system_prompt, user_query, output_size, humanize_text, reduce_words):
93
  try:
94
  completion = client.chat.completions.create(
95
  model=SUPPORTED_MODELS[model],
 
106
  except Exception as e:
107
  return f"Error: {str(e)}"
108
 
109
+ def process_response(text, output_size, bullet_points, humanize_text, reduce_words):
110
+ if reduce_words:
111
+ # Reduce word count by 50%
112
+ words = text.split()
113
+ text = " ".join(words[:len(words)//2])
114
+
115
+ if output_size == "1-3 word sentences":
116
+ text = reduce_to_sentences(text, 1, 3)
117
+ elif output_size == "2-5 word sentences":
118
  text = reduce_to_sentences(text, 2, 5)
119
  elif output_size == "3-7 word sentences":
120
  text = reduce_to_sentences(text, 3, 7)
 
124
  text = reduce_to_sentences(text, 6, 11)
125
 
126
  if bullet_points:
127
+ text = reduce_to_bullet_points(text, 1, 11)
128
 
129
  if humanize_text:
130
  text = humanize(text)
 
150
  return ' '.join(filtered_sentences)
151
 
152
  def humanize(text):
153
+ # This can be replaced with a more sophisticated humanization logic as needed
154
  return text.replace(". ", ". Let's consider this further. ")
155
 
156
  st.sidebar.info("build by dw")
157
 
158
  if __name__ == "__main__":
159
+ main()