Spaces:
Runtime error
Runtime error
Update backupapp.py
Browse files- backupapp.py +80 -32
backupapp.py
CHANGED
@@ -31,7 +31,7 @@ from PyPDF2 import PdfReader
|
|
31 |
from templates import bot_template, css, user_template
|
32 |
from xml.etree import ElementTree as ET
|
33 |
|
34 |
-
# Constants
|
35 |
API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
|
36 |
API_KEY = os.getenv('API_KEY')
|
37 |
headers = {
|
@@ -172,7 +172,7 @@ def transcribe_audio(openai_key, file_path, model):
|
|
172 |
return None
|
173 |
|
174 |
def save_and_play_audio(audio_recorder):
|
175 |
-
audio_bytes = audio_recorder()
|
176 |
if audio_bytes:
|
177 |
filename = generate_filename("Recording", "wav")
|
178 |
with open(filename, 'wb') as f:
|
@@ -387,9 +387,56 @@ def get_zip_download_link(zip_file):
|
|
387 |
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
388 |
return href
|
389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
def main():
|
391 |
|
392 |
-
st.title("
|
393 |
prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
|
394 |
|
395 |
# Add Wit and Humor buttons
|
@@ -402,16 +449,17 @@ def main():
|
|
402 |
except:
|
403 |
st.write('DromeLlama is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
404 |
|
405 |
-
|
406 |
openai.api_key = os.getenv('OPENAI_KEY')
|
407 |
menu = ["txt", "htm", "xlsx", "csv", "md", "py"]
|
408 |
choice = st.sidebar.selectbox("Output File Type:", menu)
|
409 |
model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
|
|
|
|
415 |
user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
|
416 |
collength, colupload = st.columns([2,3]) # adjust the ratio as needed
|
417 |
with collength:
|
@@ -503,35 +551,35 @@ def main():
|
|
503 |
create_file(filename, user_prompt, response, should_save)
|
504 |
st.experimental_rerun()
|
505 |
|
506 |
-
|
507 |
# Feedback
|
508 |
# Step: Give User a Way to Upvote or Downvote
|
509 |
feedback = st.radio("Step 8: Give your feedback", ("๐ Upvote", "๐ Downvote"))
|
510 |
-
|
511 |
if feedback == "๐ Upvote":
|
512 |
st.write("You upvoted ๐. Thank you for your feedback!")
|
513 |
else:
|
514 |
st.write("You downvoted ๐. Thank you for your feedback!")
|
515 |
-
|
516 |
-
load_dotenv()
|
517 |
-
st.write(css, unsafe_allow_html=True)
|
518 |
-
st.header("Chat with documents :books:")
|
519 |
-
user_question = st.text_input("Ask a question about your documents:")
|
520 |
-
if user_question:
|
521 |
-
|
522 |
-
with st.sidebar:
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
|
536 |
if __name__ == "__main__":
|
537 |
-
|
|
|
|
|
|
31 |
from templates import bot_template, css, user_template
|
32 |
from xml.etree import ElementTree as ET
|
33 |
|
34 |
+
# Llama Constants
|
35 |
API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
|
36 |
API_KEY = os.getenv('API_KEY')
|
37 |
headers = {
|
|
|
172 |
return None
|
173 |
|
174 |
def save_and_play_audio(audio_recorder):
|
175 |
+
audio_bytes = audio_recorder(key='audio_recorder')
|
176 |
if audio_bytes:
|
177 |
filename = generate_filename("Recording", "wav")
|
178 |
with open(filename, 'wb') as f:
|
|
|
387 |
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
388 |
return href
|
389 |
|
390 |
+
|
391 |
+
API_URL = f'https://tonpixzfvq3791u9.us-east-1.aws.endpoints.huggingface.cloud'
|
392 |
+
headers = {
|
393 |
+
"Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
394 |
+
"Content-Type": "audio/wav"
|
395 |
+
}
|
396 |
+
|
397 |
+
def query(filename):
|
398 |
+
with open(filename, "rb") as f:
|
399 |
+
data = f.read()
|
400 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
401 |
+
return response.json()
|
402 |
+
|
403 |
+
def generate_filename(prompt, file_type):
|
404 |
+
central = pytz.timezone('US/Central')
|
405 |
+
safe_date_time = datetime.now(central).strftime("%m%d_%H%M")
|
406 |
+
replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
|
407 |
+
safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:90]
|
408 |
+
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
409 |
+
|
410 |
+
# 10. Audio recorder to Wav file:
|
411 |
+
def save_and_play_audio(audio_recorder):
|
412 |
+
audio_bytes = audio_recorder()
|
413 |
+
if audio_bytes:
|
414 |
+
filename = generate_filename("Recording", "wav")
|
415 |
+
with open(filename, 'wb') as f:
|
416 |
+
f.write(audio_bytes)
|
417 |
+
st.audio(audio_bytes, format="audio/wav")
|
418 |
+
return filename
|
419 |
+
|
420 |
+
# 9B. Speech transcription to file output - OPENAI Whisper
|
421 |
+
def transcribe_audio(filename):
|
422 |
+
output = query(filename)
|
423 |
+
return output
|
424 |
+
|
425 |
+
|
426 |
+
def whisper_main():
|
427 |
+
st.title("Speech to Text")
|
428 |
+
st.write("Record your speech and get the text.")
|
429 |
+
|
430 |
+
# Audio, transcribe, GPT:
|
431 |
+
filename = save_and_play_audio(audio_recorder)
|
432 |
+
if filename is not None:
|
433 |
+
transcription = transcribe_audio(filename)
|
434 |
+
st.write(transcription)
|
435 |
+
|
436 |
+
|
437 |
def main():
|
438 |
|
439 |
+
st.title("AI Drome Llama")
|
440 |
prompt = f"Write ten funny jokes that are tweet length stories that make you laugh. Show as markdown outline with emojis for each."
|
441 |
|
442 |
# Add Wit and Humor buttons
|
|
|
449 |
except:
|
450 |
st.write('DromeLlama is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
451 |
|
|
|
452 |
openai.api_key = os.getenv('OPENAI_KEY')
|
453 |
menu = ["txt", "htm", "xlsx", "csv", "md", "py"]
|
454 |
choice = st.sidebar.selectbox("Output File Type:", menu)
|
455 |
model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
|
456 |
+
|
457 |
+
#filename = save_and_play_audio(audio_recorder)
|
458 |
+
#if filename is not None:
|
459 |
+
# transcription = transcribe_audio(key, filename, "whisper-1")
|
460 |
+
# st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
461 |
+
# filename = None
|
462 |
+
|
463 |
user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
|
464 |
collength, colupload = st.columns([2,3]) # adjust the ratio as needed
|
465 |
with collength:
|
|
|
551 |
create_file(filename, user_prompt, response, should_save)
|
552 |
st.experimental_rerun()
|
553 |
|
|
|
554 |
# Feedback
|
555 |
# Step: Give User a Way to Upvote or Downvote
|
556 |
feedback = st.radio("Step 8: Give your feedback", ("๐ Upvote", "๐ Downvote"))
|
|
|
557 |
if feedback == "๐ Upvote":
|
558 |
st.write("You upvoted ๐. Thank you for your feedback!")
|
559 |
else:
|
560 |
st.write("You downvoted ๐. Thank you for your feedback!")
|
561 |
+
|
562 |
+
load_dotenv()
|
563 |
+
st.write(css, unsafe_allow_html=True)
|
564 |
+
st.header("Chat with documents :books:")
|
565 |
+
user_question = st.text_input("Ask a question about your documents:")
|
566 |
+
if user_question:
|
567 |
+
process_user_input(user_question)
|
568 |
+
with st.sidebar:
|
569 |
+
st.subheader("Your documents")
|
570 |
+
docs = st.file_uploader("import documents", accept_multiple_files=True)
|
571 |
+
with st.spinner("Processing"):
|
572 |
+
raw = pdf2txt(docs)
|
573 |
+
if len(raw) > 0:
|
574 |
+
length = str(len(raw))
|
575 |
+
text_chunks = txt2chunks(raw)
|
576 |
+
vectorstore = vector_store(text_chunks)
|
577 |
+
st.session_state.conversation = get_chain(vectorstore)
|
578 |
+
st.markdown('# AI Search Index of Length:' + length + ' Created.') # add timing
|
579 |
+
filename = generate_filename(raw, 'txt')
|
580 |
+
create_file(filename, raw, '', should_save)
|
581 |
|
582 |
if __name__ == "__main__":
|
583 |
+
whisper_main()
|
584 |
+
main()
|
585 |
+
|