import gradio as gr import openai from dotenv import load_dotenv load_dotenv() openai.api_key = os.getenv('OPENAI_API_KEY') assistant_id=os.getenv('ASSISTANT_ID') client = openai.OpenAI(api_key=openai.api_key) def ask_openai(question): thread = client.beta.threads.create() client.beta.threads.messages.create( thread_id=thread.id, role="user", content=question ) run = client.beta.threads.runs.create( thread_id=thread.id, ) run = client.beta.threads.runs.retrieve( thread_id=thread.id, run_id=run.id ) messages = client.beta.threads.messages.list( thread_id=thread.id ) response = next((msg for msg in messages['data'] if msg['role'] == 'assistant'), None) return response['content'][0]['text']['value'] if response else "No response." examples = [ ["My Eucalyptus tree is struggling outside in the cold weather in europe"], ["My callatea house plant is yellowing."], ["We have a catcus as work that suddently started yellowing and wilting."] ] iface = gr.Interface( fn=ask_openai, inputs=gr.Textbox(lines=5, placeholder="Hi there, I have a plant that's..."), outputs=gr.outputs.Markdown(), title="Wecome to Tonic's Bulbi Plant Doctor", description="""Introduce your plant below. Be as descriptive as possible. Respond with additional information when prompted. Save your plants with Bulbi Plant Doctor""", theme="Tonic/greenblast" ) iface.launch()