Spaces:
Runtime error
Runtime error
File size: 1,494 Bytes
d7697ac 67164b3 d7697ac d5140c7 d7697ac 3109f0f d5140c7 d7697ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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() |