DPWXY commited on
Commit
ba8dc4b
·
1 Parent(s): 7b7ad79

Update agent

Browse files
Files changed (2) hide show
  1. app.py +3 -20
  2. requirements.txt +1 -3
app.py CHANGED
@@ -8,14 +8,6 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
8
  BASE_SYSTEM_MESSAGE = "You are a pilot assistant. You should provide concise information about the questions asked."
9
  MAX_TOKENS = 1024
10
 
11
- def transcribe_audio(audio_file):
12
- with open(audio_file, "rb") as f:
13
- transcript = openai.audio.transcriptions.create(
14
- model="whisper-1",
15
- file=f
16
- )
17
- return transcript.text
18
-
19
  def get_system_message(aircraft: str) -> str:
20
  return f"{BASE_SYSTEM_MESSAGE} You are specifically knowledgeable about the {aircraft} aircraft."
21
 
@@ -39,9 +31,7 @@ def update_chat_history(history):
39
  f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history
40
  )
41
 
42
- def handle_submit(user_input, audio_input,aircraft, history):
43
- if audio_input:
44
- user_input = transcribe_audio(audio_input)
45
  if not user_input.strip():
46
  return "", history, "Please enter a question."
47
  reply = generate_response(user_input, history, aircraft)
@@ -65,17 +55,10 @@ with gr.Blocks() as demo:
65
  with gr.Row():
66
  chat_history_display = gr.Textbox(
67
  label="Conversation History",
68
- lines=4,
69
  interactive=False
70
  )
71
 
72
- with gr.Row():
73
- audio_input = gr.Audio(
74
- sources="microphone",
75
- type="filepath",
76
- label="Record Audio",
77
- )
78
-
79
  with gr.Row():
80
  user_input = gr.Textbox(
81
  label="Ask a question",
@@ -89,7 +72,7 @@ with gr.Blocks() as demo:
89
 
90
  submit_btn.click(
91
  handle_submit,
92
- inputs=[user_input, audio_input, aircraft, conversation_state],
93
  outputs=[user_input, conversation_state, chat_history_display]
94
  )
95
 
 
8
  BASE_SYSTEM_MESSAGE = "You are a pilot assistant. You should provide concise information about the questions asked."
9
  MAX_TOKENS = 1024
10
 
 
 
 
 
 
 
 
 
11
  def get_system_message(aircraft: str) -> str:
12
  return f"{BASE_SYSTEM_MESSAGE} You are specifically knowledgeable about the {aircraft} aircraft."
13
 
 
31
  f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history
32
  )
33
 
34
+ def handle_submit(user_input, aircraft, history):
 
 
35
  if not user_input.strip():
36
  return "", history, "Please enter a question."
37
  reply = generate_response(user_input, history, aircraft)
 
55
  with gr.Row():
56
  chat_history_display = gr.Textbox(
57
  label="Conversation History",
58
+ lines=3,
59
  interactive=False
60
  )
61
 
 
 
 
 
 
 
 
62
  with gr.Row():
63
  user_input = gr.Textbox(
64
  label="Ask a question",
 
72
 
73
  submit_btn.click(
74
  handle_submit,
75
+ inputs=[user_input, aircraft, conversation_state],
76
  outputs=[user_input, conversation_state, chat_history_display]
77
  )
78
 
requirements.txt CHANGED
@@ -1,3 +1 @@
1
- openai
2
- fastapi==0.112.2
3
- gradio==4.43.0
 
1
+ openai