import gradio as gr import openai, os from huggingface_hub import Repository from io import BytesIO from dotenv import load_dotenv from openai.embeddings_utils import get_embedding, cosine_similarity from ml_to_nl_translation.translation import getTranslations, getJSONDF from lookups.translate_pdf_to_text import PreparePDF from lookups.create_searchable_content import CreateSearchableContent from utilities import api_keys import PyPDF2 import pkg_resources pypdf_version = pkg_resources.get_distribution("PyPDF2").version print(f"python-pypdf_version version: {pypdf_version}") openai.api_key = api_keys.APIKeys().get_key('OPENAI_API_KEY') eleven_api_key = api_keys.APIKeys().get_key('ELEVEN_LABS_API_KEY') voice_id = api_keys.APIKeys().get_key('VOICE_ID') def fetch_translation(): result=getTranslations() print("translator_wrapper") print (result) return result def fetch_json_html(): #reminder - this should reference a method that returns html, keeping as example result = getJSONDF() print("result") print(result) return f"
{result}
" def fetch_json_df(): result = getJSONDF() print(result) return result def fetch_reference(): result = PreparePDF() print("Result"+result) return result def fetch_content(): result = CreateSearchableContent() return result with gr.Blocks() as ui1: with gr.Row(): b1 = gr.Button("Get Sensor Data") with gr.Row(): with gr.Column(scale=1, min_width=600): df1 =gr.Dataframe(type="pandas") b1.click(fetch_json_df,outputs=df1) with gr.Blocks() as ui2: with gr.Row(): b2 = gr.Button("NLP Translate") with gr.Row(): with gr.Column(scale=1, min_width=600): df2 =gr.Dataframe(type="pandas") b2.click(fetch_translation,outputs=df2) with gr.Blocks() as ui3: with gr.Row(): b3 = gr.Button("Pull Reference") with gr.Row(): with gr.Column(scale=1, min_width=600): df3 =gr.HTML() b3.click(fetch_reference,outputs=df3) with gr.Blocks() as ui4: with gr.Row(): b4 = gr.Button("Create Searchable Content") with gr.Row(): with gr.Column(scale=1, min_width=600): df4 =gr.Dataframe(type="pandas") b4.click(fetch_content,outputs=df4) demo = gr.TabbedInterface([ui1,ui2,ui3,ui4], ("Sensor Data", "NLP Translation", "Pull Reference","Create Embeddings")) demo.launch()