Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import anthropic
|
| 3 |
import openai
|
| 4 |
-
import base64
|
| 5 |
-
from datetime import datetime
|
| 6 |
-
import pytz
|
| 7 |
import os
|
| 8 |
-
import re
|
| 9 |
import time
|
| 10 |
-
import
|
| 11 |
-
from io import BytesIO
|
| 12 |
-
from gradio_client import Client
|
| 13 |
-
from PIL import Image
|
| 14 |
import glob
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
# 1. Configuration and Setup
|
| 18 |
Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
|
|
@@ -37,46 +31,41 @@ st.set_page_config(
|
|
| 37 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 38 |
anthropic_key = os.getenv("ANTHROPIC_API_KEY_3")
|
| 39 |
|
| 40 |
-
openai_client = openai.
|
| 41 |
claude_client = anthropic.Anthropic(api_key=anthropic_key)
|
| 42 |
|
| 43 |
# Initialize session states
|
| 44 |
if 'voice_transcript' not in st.session_state:
|
| 45 |
st.session_state.voice_transcript = ""
|
| 46 |
-
|
|
|
|
| 47 |
st.session_state.chat_history = []
|
| 48 |
-
if "messages" not in st.session_state:
|
| 49 |
-
st.session_state.messages = []
|
| 50 |
|
| 51 |
# 3. Speech Recognition HTML Component
|
| 52 |
speech_recognition_html = """
|
| 53 |
<!DOCTYPE html>
|
| 54 |
<html>
|
| 55 |
<head>
|
| 56 |
-
<title>Continuous Speech
|
| 57 |
<script>
|
| 58 |
if (!('webkitSpeechRecognition' in window)) {
|
| 59 |
alert('Speech recognition not supported');
|
| 60 |
} else {
|
| 61 |
const recognition = new webkitSpeechRecognition();
|
| 62 |
-
let fullTranscript = '';
|
| 63 |
recognition.continuous = true;
|
| 64 |
recognition.interimResults = true;
|
|
|
|
| 65 |
|
| 66 |
recognition.onresult = (event) => {
|
| 67 |
-
let finalTranscript = '';
|
| 68 |
for (let i = event.resultIndex; i < event.results.length; i++) {
|
| 69 |
if (event.results[i].isFinal) {
|
| 70 |
finalTranscript += event.results[i][0].transcript + '\\n';
|
| 71 |
}
|
| 72 |
}
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
text: finalTranscript
|
| 78 |
-
}, '*');
|
| 79 |
-
}
|
| 80 |
};
|
| 81 |
|
| 82 |
recognition.start();
|
|
@@ -90,21 +79,20 @@ speech_recognition_html = """
|
|
| 90 |
# Helper Functions
|
| 91 |
def process_with_gpt(text_input):
|
| 92 |
if text_input:
|
| 93 |
-
completion = openai_client.
|
| 94 |
-
model="gpt-
|
| 95 |
-
messages=[{"role": "user", "content": text_input}]
|
| 96 |
-
max_tokens=500,
|
| 97 |
)
|
| 98 |
-
return completion
|
| 99 |
|
| 100 |
def process_with_claude(text_input):
|
| 101 |
if text_input:
|
| 102 |
-
response = claude_client.
|
| 103 |
-
model="claude-
|
| 104 |
-
messages=[{"role": "user", "content": text_input}],
|
| 105 |
max_tokens=1000,
|
|
|
|
| 106 |
)
|
| 107 |
-
return response
|
| 108 |
|
| 109 |
def perform_ai_lookup(query):
|
| 110 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
|
@@ -115,23 +103,25 @@ def perform_ai_lookup(query):
|
|
| 115 |
return response
|
| 116 |
|
| 117 |
def display_file_manager():
|
| 118 |
-
"""Display file management sidebar."""
|
| 119 |
st.sidebar.title("📁 File Management")
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
-
if st.sidebar.button("
|
| 124 |
-
for file in
|
| 125 |
os.remove(file)
|
| 126 |
-
st.
|
| 127 |
|
| 128 |
-
if st.sidebar.button("
|
| 129 |
with zipfile.ZipFile("all_files.zip", 'w') as zipf:
|
| 130 |
-
for file in
|
| 131 |
zipf.write(file)
|
| 132 |
-
st.sidebar.markdown(
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
for file in
|
| 135 |
st.sidebar.write(file)
|
| 136 |
|
| 137 |
# Main Function
|
|
@@ -147,7 +137,7 @@ def main():
|
|
| 147 |
st.text_area("Transcript", st.session_state.voice_transcript, height=100)
|
| 148 |
|
| 149 |
if st.button("Search with GPT"):
|
| 150 |
-
st.subheader("GPT-
|
| 151 |
gpt_response = process_with_gpt(st.session_state.voice_transcript)
|
| 152 |
st.write(gpt_response)
|
| 153 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import anthropic
|
| 3 |
import openai
|
|
|
|
|
|
|
|
|
|
| 4 |
import os
|
|
|
|
| 5 |
import time
|
| 6 |
+
import base64
|
|
|
|
|
|
|
|
|
|
| 7 |
import glob
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from gradio_client import Client
|
| 10 |
|
| 11 |
# 1. Configuration and Setup
|
| 12 |
Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
|
|
|
|
| 31 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 32 |
anthropic_key = os.getenv("ANTHROPIC_API_KEY_3")
|
| 33 |
|
| 34 |
+
openai_client = openai.ChatCompletion()
|
| 35 |
claude_client = anthropic.Anthropic(api_key=anthropic_key)
|
| 36 |
|
| 37 |
# Initialize session states
|
| 38 |
if 'voice_transcript' not in st.session_state:
|
| 39 |
st.session_state.voice_transcript = ""
|
| 40 |
+
|
| 41 |
+
if 'chat_history' not in st.session_state:
|
| 42 |
st.session_state.chat_history = []
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# 3. Speech Recognition HTML Component
|
| 45 |
speech_recognition_html = """
|
| 46 |
<!DOCTYPE html>
|
| 47 |
<html>
|
| 48 |
<head>
|
| 49 |
+
<title>Continuous Speech Recognition</title>
|
| 50 |
<script>
|
| 51 |
if (!('webkitSpeechRecognition' in window)) {
|
| 52 |
alert('Speech recognition not supported');
|
| 53 |
} else {
|
| 54 |
const recognition = new webkitSpeechRecognition();
|
|
|
|
| 55 |
recognition.continuous = true;
|
| 56 |
recognition.interimResults = true;
|
| 57 |
+
let finalTranscript = '';
|
| 58 |
|
| 59 |
recognition.onresult = (event) => {
|
|
|
|
| 60 |
for (let i = event.resultIndex; i < event.results.length; i++) {
|
| 61 |
if (event.results[i].isFinal) {
|
| 62 |
finalTranscript += event.results[i][0].transcript + '\\n';
|
| 63 |
}
|
| 64 |
}
|
| 65 |
+
window.parent.postMessage({
|
| 66 |
+
type: 'final_transcript',
|
| 67 |
+
text: finalTranscript
|
| 68 |
+
}, '*');
|
|
|
|
|
|
|
|
|
|
| 69 |
};
|
| 70 |
|
| 71 |
recognition.start();
|
|
|
|
| 79 |
# Helper Functions
|
| 80 |
def process_with_gpt(text_input):
|
| 81 |
if text_input:
|
| 82 |
+
completion = openai_client.create(
|
| 83 |
+
model="gpt-4",
|
| 84 |
+
messages=[{"role": "user", "content": text_input}]
|
|
|
|
| 85 |
)
|
| 86 |
+
return completion['choices'][0]['message']['content']
|
| 87 |
|
| 88 |
def process_with_claude(text_input):
|
| 89 |
if text_input:
|
| 90 |
+
response = claude_client.completions.create(
|
| 91 |
+
model="claude-2",
|
|
|
|
| 92 |
max_tokens=1000,
|
| 93 |
+
messages=[{"role": "user", "content": text_input}]
|
| 94 |
)
|
| 95 |
+
return response['completion']
|
| 96 |
|
| 97 |
def perform_ai_lookup(query):
|
| 98 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
|
|
|
| 103 |
return response
|
| 104 |
|
| 105 |
def display_file_manager():
|
|
|
|
| 106 |
st.sidebar.title("📁 File Management")
|
| 107 |
+
files = glob.glob("*.md")
|
| 108 |
+
files.sort(reverse=True)
|
| 109 |
|
| 110 |
+
if st.sidebar.button("Delete All"):
|
| 111 |
+
for file in files:
|
| 112 |
os.remove(file)
|
| 113 |
+
st.experimental_rerun()
|
| 114 |
|
| 115 |
+
if st.sidebar.button("Download All"):
|
| 116 |
with zipfile.ZipFile("all_files.zip", 'w') as zipf:
|
| 117 |
+
for file in files:
|
| 118 |
zipf.write(file)
|
| 119 |
+
st.sidebar.markdown(
|
| 120 |
+
f'<a href="all_files.zip" download>Download All Files</a>',
|
| 121 |
+
unsafe_allow_html=True
|
| 122 |
+
)
|
| 123 |
|
| 124 |
+
for file in files:
|
| 125 |
st.sidebar.write(file)
|
| 126 |
|
| 127 |
# Main Function
|
|
|
|
| 137 |
st.text_area("Transcript", st.session_state.voice_transcript, height=100)
|
| 138 |
|
| 139 |
if st.button("Search with GPT"):
|
| 140 |
+
st.subheader("GPT-4 Response")
|
| 141 |
gpt_response = process_with_gpt(st.session_state.voice_transcript)
|
| 142 |
st.write(gpt_response)
|
| 143 |
|