bai4578 commited on
Commit
81f8ec2
·
verified ·
1 Parent(s): 02087c9

Update app.py

Browse files

frst attempt prompt from string

Files changed (1) hide show
  1. app.py +32 -8
app.py CHANGED
@@ -4,6 +4,8 @@ import shutil
4
  from groq import Groq
5
  import gradio as gr
6
  from pydub import AudioSegment
 
 
7
 
8
  # Initialize the Groq client
9
  client = Groq(api_key=os.environ["keko"])
@@ -248,16 +250,38 @@ def transcribe_audio(audio_file):
248
 
249
 
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  def generate_text(text, prompt_type):
252
  if not text:
253
  return "No text provided."
254
 
255
- prompts = {
256
- "dic_clean":"You will receive a chunk of dictated text (via speech to text), domain is likely medical/gastroenterology. correct the text while maintaining the original tone and style but correct spelling and replace punctuation and newline wordings. Also follow inline corrections as dictated by the user (eg delete, replace, go back, rewrite, etc...). pay attention to correct gender he/she throughout to make sure it matches. pay attention to words that could have been mis transcribed during the speech to text conversion and correct it to the best of your ability. if you are uncertain about a word, put it in doube square brackets. The output should be the corrected text only, without any quotes or comments or feedback.",
257
- "summarize": "You are an AI assistant specialized in summarizing text. Provide a concise summary of the given text.",
258
- "create_qa": "You are an AI assistant specialized in creating Q&A pairs. Generate relevant questions and answers based on the given text.",
259
- "analyze": "You are an AI assistant specialized in text analysis. Analyze the main points and key ideas of the given text."
260
- }
261
 
262
  selected_prompt = prompts.get(prompt_type, "You are a helpful assistant. Process the following text.")
263
 
@@ -340,9 +364,9 @@ with gr.Blocks(title="Audio Recorder, Transcriber, and Text Generator") as demo:
340
 
341
  with gr.Row():
342
  prompt_type = gr.Dropdown(
343
- choices=["dic_clean", "summarize", "create_qa", "analyze"],
344
  label="Select Text Generation Type",
345
- value="dic_clean"
346
  )
347
  generate_btn = gr.Button("Generate Text")
348
 
 
4
  from groq import Groq
5
  import gradio as gr
6
  from pydub import AudioSegment
7
+ import re
8
+
9
 
10
  # Initialize the Groq client
11
  client = Groq(api_key=os.environ["keko"])
 
250
 
251
 
252
 
253
+
254
+
255
+
256
+ ## function to parse text into dictionary of prompts
257
+ def parse_text_to_dict(text):
258
+ sections = re.split(r"\n#/\s*", text.strip()) # Split only at "#/"
259
+ parsed_dict = {}
260
+
261
+ for section in sections:
262
+ if not section.strip(): # Skip empty sections
263
+ continue
264
+ lines = section.split("\n", 1) # Split into title and content
265
+ title = lines[0].strip().lstrip("#/ ") # Ensure "#/" is removed
266
+ content = lines[1].strip() if len(lines) > 1 else "" # Remaining text is the value
267
+ parsed_dict[title] = content
268
+
269
+ return parsed_dict
270
+
271
+ # load the prompts:
272
+
273
+ with open("primpts.txt", "r", encoding="utf-8") as file:
274
+ contentt = file.read()
275
+
276
+ contentt = parse_text_to_dict(contentt)
277
+
278
+
279
+
280
  def generate_text(text, prompt_type):
281
  if not text:
282
  return "No text provided."
283
 
284
+ prompts = contentt
 
 
 
 
 
285
 
286
  selected_prompt = prompts.get(prompt_type, "You are a helpful assistant. Process the following text.")
287
 
 
364
 
365
  with gr.Row():
366
  prompt_type = gr.Dropdown(
367
+ choices=list(prompts.keys()), # Get dictionary keys as choices
368
  label="Select Text Generation Type",
369
+ value=list(prompts.keys())[0] # Default to the first key
370
  )
371
  generate_btn = gr.Button("Generate Text")
372