huohguohbo commited on
Commit
d92408a
·
1 Parent(s): 8eead85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -37
app.py CHANGED
@@ -37,52 +37,29 @@ def hf_chat(model_name, message):
37
 
38
  return bot_response
39
 
40
- # Define the Gradio interface for OpenAI chatbot
41
  api_key_input = gr.inputs.Textbox(label="OpenAI API Key", default=None)
42
  model_input = gr.inputs.Dropdown(
43
  label="Select OpenAI model",
44
  choices=["davinci", "curie", "babbage"],
45
  default="davinci",
46
  )
47
- message_input = gr.inputs.Textbox(label="Enter your message here")
48
- output = gr.outputs.Textbox(label="Bot response")
49
-
50
- openai_chat_button = gr.Interface(
51
- fn=openai_chat,
52
- inputs=[api_key_input, model_input, message_input],
53
- outputs=output,
54
- title="OpenAI Chatbot",
55
- description="Enter your message below to chat with an OpenAI AI",
56
- theme="compact",
57
- layout="vertical",
58
- allow_flagging=False,
59
- allow_screenshot=False,
60
- allow_share=False,
61
- )
62
-
63
- # Define the Gradio interface for Hugging Face chatbot
64
  hf_model_input = gr.inputs.Dropdown(
65
  label="Select Hugging Face model",
66
  choices=["microsoft/DialoGPT-large", "microsoft/DialoGPT-medium", "microsoft/DialoGPT-small"],
67
  default="microsoft/DialoGPT-large",
68
  )
69
-
70
- hf_chat_button = gr.Interface(
71
- fn=hf_chat,
72
- inputs=[hf_model_input, message_input],
73
- outputs=output,
74
- title="Hugging Face Chatbot",
75
- description="Enter your message below to chat with a Hugging Face AI",
76
- theme="compact",
77
- layout="vertical",
78
- allow_flagging=False,
79
- allow_screenshot=False,
80
- allow_share=False,
81
  )
 
 
82
 
83
  chat_button = gr.Interface(
84
- fn=lambda message, model, hf_model, api_key: hf_chat(hf_model, message) if hf_model else openai_chat(api_key, model, message),
85
- inputs=[message_input, model_input, hf_model_input, api_key_input],
86
  outputs=output,
87
  title="Chatbot",
88
  description="Enter your message below to chat with an AI",
@@ -91,11 +68,10 @@ chat_button = gr.Interface(
91
  allow_screenshot=False,
92
  allow_share=False,
93
  examples=[
94
- ["Hello, how are you?", "", "", None],
95
- ["What's the weather like today?", "", "", None],
96
- ["Can you help me with some Python code?", "```python\nfor i in range(10):\n print(i)\n```", "", None],
97
  ],
98
- live=False,
99
  )
100
 
101
- chat_button.launch() # Launch the Gradio interface
 
37
 
38
  return bot_response
39
 
40
+ # Define the Gradio interface for chatbot
41
  api_key_input = gr.inputs.Textbox(label="OpenAI API Key", default=None)
42
  model_input = gr.inputs.Dropdown(
43
  label="Select OpenAI model",
44
  choices=["davinci", "curie", "babbage"],
45
  default="davinci",
46
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  hf_model_input = gr.inputs.Dropdown(
48
  label="Select Hugging Face model",
49
  choices=["microsoft/DialoGPT-large", "microsoft/DialoGPT-medium", "microsoft/DialoGPT-small"],
50
  default="microsoft/DialoGPT-large",
51
  )
52
+ mode_input = gr.inputs.Dropdown(
53
+ label="Select chatbot mode",
54
+ choices=["OpenAI", "Hugging Face"],
55
+ default="OpenAI",
 
 
 
 
 
 
 
 
56
  )
57
+ message_input = gr.inputs.Textbox(label="Enter your message here")
58
+ output = gr.outputs.Textbox(label="Bot response")
59
 
60
  chat_button = gr.Interface(
61
+ fn=lambda message, model, hf_model, api_key, mode: hf_chat(hf_model, message) if mode == "Hugging Face" else openai_chat(api_key, model, message),
62
+ inputs=[message_input, model_input, hf_model_input, api_key_input, mode_input],
63
  outputs=output,
64
  title="Chatbot",
65
  description="Enter your message below to chat with an AI",
 
68
  allow_screenshot=False,
69
  allow_share=False,
70
  examples=[
71
+ ["Hello, how are you?", "", "", None, "OpenAI"],
72
+ ["What's the weather like today?", "", "", None, "Hugging Face"],
73
+ ["Can you help me with some Python code?", "```python\nfor i in range(10):\n print(i)\n```", "", None, "OpenAI"],
74
  ],
 
75
  )
76
 
77
+ gradio.launch(chat_button)