shambhavisrege commited on
Commit
5562770
·
1 Parent(s): b99d7cf

update app

Browse files
Files changed (1) hide show
  1. app.py +42 -13
app.py CHANGED
@@ -1,5 +1,6 @@
1
- import openai
2
  import gradio as gr
 
3
 
4
  # openai.api_key = "MY_API_KEY"
5
 
@@ -20,27 +21,51 @@ import gradio as gr
20
  import random
21
  import time
22
 
23
- with gr.Blocks() as demo:
24
- chatbot = gr.Chatbot()
25
- msg = gr.Textbox()
26
- clear = gr.Button("Clear")
27
-
28
- def user(user_message, history):
29
- return "", history + [[user_message, None]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- def bot(history, user_message):
32
- #bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
33
 
 
 
34
  qs = {'hello': 'hi, how can i help you?', 'hi': 'hi, how can i help you?', 'restaurants': "New York City boasts a diverse culinary scene. Notable restaurants include fine dining establishments like Per Se, iconic pizzerias like Di Fara Pizza, classic delis like Katz's, and trendy spots like Momofuku Noodle Bar. Options range from Italian at Lilia to Asian fusion at Mission Chinese Food, with diverse choices reflecting the city's international influences. Explore neighborhoods for hidden gems, and iconic markets like Chelsea Market offer a variety of food experiences.", 'president': 'As of my last knowledge update in January 2022, Joe Biden was the President of the United States. However, please note that my information might be outdated, as I do not have real-time capabilities. I recommend checking the latest reliable sources for the most current information on the President of the United States.', 'moon': "The Moon is Earth's only natural satellite, formed about 4.5 billion years ago. It has a diameter of 3,474 kilometers, 1/6th of Earth's gravity, and features like craters, mountains, and lunar maria. The Moon has no significant atmosphere, experiences phases due to its orbit, and was explored by astronauts during the Apollo missions. Future plans include returning to the Moon for exploration and potential habitation.",
35
  'gogh': "Vincent van Gogh (1853–1890) was a Dutch post-impressionist painter. He is renowned for his expressive use of color, bold brushstrokes, and emotional intensity in works like Starry Night and Sunflowers. Despite struggling with mental health issues throughout his life, van Gogh created over 2,000 artworks, but he only gained widespread recognition after his death. His impact on art and his unique style have made him an enduring figure in the history of Western art."}
36
 
37
  def chat(input):
38
- for q in set(input.lower().split()):
39
  if q in qs:
40
  return qs[q]
41
-
 
42
  bot_message = chat(user_message)
43
 
 
 
 
 
 
 
 
44
  history[-1][1] = ""
45
  for character in bot_message:
46
  history[-1][1] += character
@@ -50,7 +75,11 @@ with gr.Blocks() as demo:
50
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
51
  bot, chatbot, chatbot
52
  )
53
- clear.click(lambda: None, None, chatbot, queue=False)
 
 
 
 
54
 
55
  demo.queue()
56
  demo.launch()
 
1
+ #import openai
2
  import gradio as gr
3
+ import os
4
 
5
  # openai.api_key = "MY_API_KEY"
6
 
 
21
  import random
22
  import time
23
 
24
+ theme = gr.themes.Base(
25
+ primary_hue="gray",
26
+ secondary_hue="gray",
27
+ ).set(
28
+ background_fill_primary_dark='*block_title_background_fill',
29
+ background_fill_secondary_dark='*neutral_950'
30
+ )
31
+
32
+ with gr.Blocks(theme = theme) as demo:
33
+ chatbot = gr.Chatbot(value = [], elem_id="chatbot", layout = "panel",
34
+ avatar_images=((os.path.join(os.path.dirname(__file__), "usericon.jpeg")), (os.path.join(os.path.dirname(__file__), "chatboticon.jpeg"))))
35
+
36
+ with gr.Row():
37
+ with gr.Column(min_width=200, scale=10):
38
+ msg = gr.Textbox(
39
+ show_label=False,
40
+ placeholder="Enter text and press enter",
41
+ max_lines = 5,
42
+ container = False,
43
+
44
+ )
45
+ with gr.Column(min_width = 42, scale= 1):
46
+ btn = gr.Button(value="⬆︎")
47
 
 
 
48
 
49
+
50
+ def user(user_message, history):
51
  qs = {'hello': 'hi, how can i help you?', 'hi': 'hi, how can i help you?', 'restaurants': "New York City boasts a diverse culinary scene. Notable restaurants include fine dining establishments like Per Se, iconic pizzerias like Di Fara Pizza, classic delis like Katz's, and trendy spots like Momofuku Noodle Bar. Options range from Italian at Lilia to Asian fusion at Mission Chinese Food, with diverse choices reflecting the city's international influences. Explore neighborhoods for hidden gems, and iconic markets like Chelsea Market offer a variety of food experiences.", 'president': 'As of my last knowledge update in January 2022, Joe Biden was the President of the United States. However, please note that my information might be outdated, as I do not have real-time capabilities. I recommend checking the latest reliable sources for the most current information on the President of the United States.', 'moon': "The Moon is Earth's only natural satellite, formed about 4.5 billion years ago. It has a diameter of 3,474 kilometers, 1/6th of Earth's gravity, and features like craters, mountains, and lunar maria. The Moon has no significant atmosphere, experiences phases due to its orbit, and was explored by astronauts during the Apollo missions. Future plans include returning to the Moon for exploration and potential habitation.",
52
  'gogh': "Vincent van Gogh (1853–1890) was a Dutch post-impressionist painter. He is renowned for his expressive use of color, bold brushstrokes, and emotional intensity in works like Starry Night and Sunflowers. Despite struggling with mental health issues throughout his life, van Gogh created over 2,000 artworks, but he only gained widespread recognition after his death. His impact on art and his unique style have made him an enduring figure in the history of Western art."}
53
 
54
  def chat(input):
55
+ for q in set(input.lower().split()):
56
  if q in qs:
57
  return qs[q]
58
+ else:
59
+ return "Sorry, I don't know"
60
  bot_message = chat(user_message)
61
 
62
+ return "", history + [[user_message, bot_message]]
63
+
64
+ def bot(history):
65
+ print(history)
66
+ # bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
67
+ #history[-1][1] = ""
68
+ bot_message = history[-1][1]
69
  history[-1][1] = ""
70
  for character in bot_message:
71
  history[-1][1] += character
 
75
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
76
  bot, chatbot, chatbot
77
  )
78
+ btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
79
+ bot, chatbot, chatbot
80
+ )
81
+
82
+
83
 
84
  demo.queue()
85
  demo.launch()