import streamlit as st
import anthropic
import openai
import os
import time
import base64
import glob
from datetime import datetime
from gradio_client import Client
# 1. Configuration and Setup
Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
title = "🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI"
helpURL = 'https://huggingface.co/awacke1'
bugURL = 'https://huggingface.co/spaces/awacke1'
icons = '🚲🏆'
st.set_page_config(
page_title=title,
page_icon=icons,
layout="wide",
initial_sidebar_state="auto",
menu_items={
'Get Help': helpURL,
'Report a bug': bugURL,
'About': title
}
)
# 2. Load environment variables and initialize clients
openai.api_key = os.getenv('OPENAI_API_KEY')
anthropic_key = os.getenv("ANTHROPIC_API_KEY_3")
openai_client = openai.ChatCompletion()
claude_client = anthropic.Anthropic(api_key=anthropic_key)
# Initialize session states
if 'voice_transcript' not in st.session_state:
st.session_state.voice_transcript = ""
if 'chat_history' not in st.session_state:
st.session_state.chat_history = []
# 3. Speech Recognition HTML Component
speech_recognition_html = """
Continuous Speech Recognition
"""
# Helper Functions
def process_with_gpt(text_input):
if text_input:
completion = openai_client.create(
model="gpt-4",
messages=[{"role": "user", "content": text_input}]
)
return completion['choices'][0]['message']['content']
def process_with_claude(text_input):
if text_input:
response = claude_client.completions.create(
model="claude-2",
max_tokens=1000,
messages=[{"role": "user", "content": text_input}]
)
return response['completion']
def perform_ai_lookup(query):
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
response = client.predict(
prompt=query,
api_name="/ask_llm"
)
return response
def display_file_manager():
st.sidebar.title("📁 File Management")
files = glob.glob("*.md")
files.sort(reverse=True)
if st.sidebar.button("Delete All"):
for file in files:
os.remove(file)
st.experimental_rerun()
if st.sidebar.button("Download All"):
with zipfile.ZipFile("all_files.zip", 'w') as zipf:
for file in files:
zipf.write(file)
st.sidebar.markdown(
f'Download All Files',
unsafe_allow_html=True
)
for file in files:
st.sidebar.write(file)
# Main Function
def main():
st.sidebar.markdown("### 🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI")
tab_main = st.radio("Choose Action:", ["🎤 Voice Input", "💬 Chat", "🔍 Search ArXiv"], horizontal=True)
if tab_main == "🎤 Voice Input":
st.subheader("Voice Recognition")
st.components.v1.html(speech_recognition_html, height=300)
if st.session_state.voice_transcript:
st.text_area("Transcript", st.session_state.voice_transcript, height=100)
if st.button("Search with GPT"):
st.subheader("GPT-4 Response")
gpt_response = process_with_gpt(st.session_state.voice_transcript)
st.write(gpt_response)
if st.button("Search with Claude"):
st.subheader("Claude Response")
claude_response = process_with_claude(st.session_state.voice_transcript)
st.write(claude_response)
if st.button("Search ArXiv"):
st.subheader("ArXiv Search Results")
arxiv_results = perform_ai_lookup(st.session_state.voice_transcript)
st.write(arxiv_results)
if st.button("Clear Transcript"):
st.session_state.voice_transcript = ""
elif tab_main == "💬 Chat":
st.subheader("Chat")
user_input = st.text_area("Your Message", height=100)
if st.button("Send"):
if user_input:
gpt_response = process_with_gpt(user_input)
st.write("GPT Response:", gpt_response)
claude_response = process_with_claude(user_input)
st.write("Claude Response:", claude_response)
elif tab_main == "🔍 Search ArXiv":
query = st.text_input("Enter your research query:")
if query:
results = perform_ai_lookup(query)
st.write(results)
display_file_manager()
if __name__ == "__main__":
main()