HanYangHanYang commited on
Commit
8b6e3d9
1 Parent(s): 4e62fee

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +38 -2
  2. virtual_human.py +2 -2
  3. web_demo.py +34 -15
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
 
4
  class Human:
@@ -13,8 +14,8 @@ class Human:
13
  self.count += 1
14
  return "this round:"+str(self.count)
15
 
16
- h = Human()
17
- hs = gr.State(h)
18
 
19
  def output(message, history, s):
20
  r = s.echo(message, history)
@@ -22,6 +23,7 @@ def output(message, history, s):
22
 
23
 
24
 
 
25
  demo = gr.ChatInterface(
26
  fn=output,
27
  additional_inputs=[hs],
@@ -31,4 +33,38 @@ demo = gr.ChatInterface(
31
  #clear_btn="再来一局",
32
  clear_btn=gr.ClearButton(hs),
33
  title="Echo Bot")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  demo.launch()
 
 
 
 
 
1
  import gradio as gr
2
+ import random
3
 
4
 
5
  class Human:
 
14
  self.count += 1
15
  return "this round:"+str(self.count)
16
 
17
+ #h = Human()
18
+ #hs = gr.State(h)
19
 
20
  def output(message, history, s):
21
  r = s.echo(message, history)
 
23
 
24
 
25
 
26
+ '''
27
  demo = gr.ChatInterface(
28
  fn=output,
29
  additional_inputs=[hs],
 
33
  #clear_btn="再来一局",
34
  clear_btn=gr.ClearButton(hs),
35
  title="Echo Bot")
36
+ '''
37
+ def respond(message, history, state):
38
+ bot_message = state.echo(message, history)
39
+ history.append((message, bot_message))
40
+ return "", history, state
41
+
42
+ def cl(message, history, state):
43
+ message = ""
44
+ history.clear()
45
+ state.reset()
46
+ return "", history, state
47
+
48
+
49
+ with gr.Blocks() as demo:
50
+
51
+ label = gr.Label("hello world")
52
+ html = gr.HTML("<h1>Greeting App</h1> \
53
+ <p>This app greets people.</p>")
54
+ chatbot = gr.Chatbot(label="heoo world", value=[('ff','bb'),('cc','dd')])
55
+ msg = gr.Textbox()
56
+ submit = gr.Button("发送" )
57
+ clear = gr.ClearButton()
58
+
59
+ h = Human()
60
+ state = gr.State(h)
61
+
62
+
63
+ clear.click(cl, [msg, chatbot, state], [msg, chatbot, state])
64
+ submit.click(respond, [msg, chatbot, state], [msg, chatbot, state])
65
+
66
  demo.launch()
67
+
68
+
69
+
70
+
virtual_human.py CHANGED
@@ -197,8 +197,8 @@ class VirtualHuman:
197
  gr.Info('挑战失败,女生已删除你的好友')
198
  return reply + ' 【挑战失败,女生已删除你的好友】'
199
  elif state == "ongoing":
200
- #return f'【亲密度:{closeness}】:{reply}【{rounds}/{self._conversation_rounds_threshold}】'
201
- return f'{reply}【{rounds}/{self._conversation_rounds_threshold}】'
202
  elif state == "gameover":
203
  return f'游戏结束,请输入"再来一局"以重新开始'
204
 
 
197
  gr.Info('挑战失败,女生已删除你的好友')
198
  return reply + ' 【挑战失败,女生已删除你的好友】'
199
  elif state == "ongoing":
200
+ return f'【亲密度:{closeness}】:{reply}【{rounds}/{self._conversation_rounds_threshold}】'
201
+ #return f'{reply}【{rounds}/{self._conversation_rounds_threshold}】'
202
  elif state == "gameover":
203
  return f'游戏结束,请输入"再来一局"以重新开始'
204
 
web_demo.py CHANGED
@@ -1,20 +1,39 @@
1
  import gradio as gr
2
  from virtual_human import VirtualHuman
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- vh = VirtualHuman()
6
- state = gr.State(vh)
7
 
8
- def gradio_interface(message, history, state):
9
- return state.gradio_interface(message, history)
10
-
11
- gr.ChatInterface(fn=gradio_interface,
12
- additional_inputs=[state],
13
- retry_btn=None,
14
- undo_btn=None,
15
- submit_btn="发送",
16
- clear_btn=None,
17
- title="任务:获得女生好感,好感度提升可以看女生照片",
18
- description="背景信息:你通过朋友的介绍,加入了一个微信群,这是一个讨论文学与艺术的群组。\
19
- 有一天,你注意到群里有一个特别引人注目的成员,ID为远方的梦,她的头像是一朵粉色的玫瑰花,\
20
- 没有个人资料,只是在群里偶尔发一些有深度的文学感悟。你加了她的微信,她刚刚通过好友验证.【输入“再来一局” 重新开始】").launch()
 
1
  import gradio as gr
2
  from virtual_human import VirtualHuman
3
 
4
+ def gradio_interface(message, history, state):
5
+ response = state.gradio_interface(message, history)
6
+ history.append((message, response))
7
+ return "", history, state
8
+
9
+ def try_again(message, history, state):
10
+ message = ""
11
+ history=[(None, "我通过了你的朋友验证请求,现在我们可以开始聊天了")]
12
+ state.reset()
13
+ return "", history, state
14
+
15
+
16
+ with gr.Blocks() as demo:
17
+ html = gr.HTML("<h1> 任务:获得女生好感,好感度提升可以看女生照片 </h1> \
18
+ <p> 背景信息:你通过朋友的介绍,加入了一个微信群,这是一个讨论文学与艺术的群组。 \
19
+ 有一天,你注意到群里有一个特别引人注目的成员,ID为远方的梦,她的头像是一朵粉色的玫瑰花,\
20
+ 没有个人资料,只是在群里偶尔发一些有深度的文学感悟。你加了她的微信,她刚刚通过好友验证。 </p>")
21
+
22
+ chatbot = gr.Chatbot(value=[(None, "我通过了你的朋友验证请求,现在我们可以开始聊天了")])
23
+ msg = gr.Textbox()
24
+ send = gr.Button("发送")
25
+ clear = gr.Button("再来一局")
26
+
27
+ vh = VirtualHuman()
28
+ state = gr.State(vh)
29
+
30
+ send.click(gradio_interface, [msg, chatbot, state], [msg, chatbot, state])
31
+ clear.click(try_again, [msg, chatbot, state], [msg, chatbot, state])
32
+
33
+ demo.launch()
34
+
35
+
36
+
37
+
38
 
 
 
39