Spaces:
Sleeping
Sleeping
File size: 2,398 Bytes
9ef95c7 e616d10 83b6e89 9ef95c7 83b6e89 e616d10 9ef95c7 83b6e89 9ef95c7 83b6e89 e616d10 83b6e89 9ef95c7 83b6e89 e616d10 83b6e89 9ef95c7 83b6e89 9ef95c7 83b6e89 9ef95c7 83b6e89 9ef95c7 | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import gradio as gr
import openai
import os
import random
import json
# Set OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_random_turn_data():
"""Generates random flight turn data."""
data_points = []
for point in range(10):
data_points.append({
"Point": point * 36,
"ASI": random.randint(85, 100), # Airspeed Indicator in knots
"AI": "level",
"Heading": random.randint(0, 359), # Heading in degrees
"Turn and Slip": random.choice(["turn needle left", "turn needle right", "centered"]),
"Bank Angle": random.choice([-45, -40, -35, 35, 40, 45]),
"VSI": random.choice([-100, -50, 0, 50, 100]) # Vertical Speed Indicator in feet per minute
})
# Format data for display
input_blocks = ["\n".join([f"{key}: {value}" for key, value in point.items()]) for point in data_points]
return "\n\n".join(input_blocks)
def respond(message, history: list[tuple[str, str]]):
"""Handles chat responses using OpenAI."""
messages = [{"role": "system", "content": "Evaluate the flight turn data"}]
for user_msg, assistant_msg in history:
if user_msg:
messages.append({"role": "user", "content": user_msg})
if assistant_msg:
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
response = openai.chat.completions.create(
model="ft:gpt-4o-2024-08-06:personal::BAk7EUnu",
messages=messages
)
return response.choices[0].message.content
def get_random_turn_data():
"""Returns randomly generated flight turn data."""
return generate_random_turn_data()
demo = gr.ChatInterface(respond)
demo = gr.Blocks()
with demo:
gr.Markdown("# Flight Turn Data Evaluator")
with gr.Row():
user_input = gr.Textbox(label="Enter Flight Turn Data or Generate Random Data")
with gr.Row():
submit_button = gr.Button("Submit")
random_button = gr.Button("Random Generate")
with gr.Row():
output_display = gr.Textbox(label="Response", interactive=False)
submit_button.click(respond, inputs=[user_input, gr.State([])], outputs=output_display)
random_button.click(get_random_turn_data, inputs=[], outputs=user_input)
if __name__ == "__main__":
demo.launch()
|