ldhldh commited on
Commit
d32111b
Β·
1 Parent(s): 080601a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -42
app.py CHANGED
@@ -3,14 +3,12 @@ from gradio_client import Client as GrClient
3
  import inspect
4
  from gradio import routes
5
  from typing import List, Type
6
- from aiogoogletrans import Translator
7
 
8
  import requests, os, re, asyncio
9
 
10
 
11
  loop = asyncio.get_event_loop()
12
- gradio_client = GrClient(os.environ.get('GrClient_url2'))
13
- translator = Translator()
14
  # Monkey patch
15
  def get_types(cls_set: List[Type], component: str):
16
  docset = []
@@ -30,25 +28,10 @@ def get_types(cls_set: List[Type], component: str):
30
  return docset, types
31
  routes.get_types = get_types
32
 
33
-
34
  # App code
35
- def mbti(x):
36
- t = loop.run_until_complete(translator.translate(x, src='ko', dest='en'))
37
- str_trans = re.sub('[-=+,#/\?:^.@*\"β€»~ㆍ!γ€β€˜|\(\)\[\]`\'…》\”\β€œ\’·]', '', t.text)
38
- result = gradio_client.predict(
39
- str_trans, # str representing input in 'User input' Textbox component
40
- fn_index=2
41
- )
42
- r = sorted(eval(result), key=lambda x : x['score'], reverse=True)
43
-
44
- return r
45
-
46
  def chat(x):
47
- x = f"[***λ„ˆλŠ” Assistantμž…λ‹ˆλ‹€. μƒλŒ€μ—κ²Œ λ‹€μ–‘ν•œ μ§ˆλ¬Έμ„ ν•˜λ©° λŒ€ν™”λ₯Ό 이끌고 μžˆμŠ΅λ‹ˆλ‹€. Humanμ—κ²Œ 긍정적이고, κ³΅κ°ν•˜λ©°, μ΅œλŒ€ν•œ 길게 λŒ€λ‹΅ν•΄μ£Όμ„Έμš”***] {x}"
48
- x = x.replace('friend','Human').replace('you','Assistant')
49
- x_list = x.rsplit('\n',1)
50
 
51
- x = x_list[0]+"\n\n### \n"+x_list[1]
52
  print("\n___________________\n" + f"{x}")
53
  result = gradio_client.predict(
54
  x,
@@ -70,13 +53,6 @@ def chat(x):
70
 
71
  return output
72
 
73
- def yn(x):
74
- result = gradio_client.predict(
75
- x, # str representing input in 'User input' Textbox component
76
- fn_index=1
77
- )
78
- return result
79
-
80
  with gr.Blocks() as demo:
81
  count = 0
82
  aa = gr.Interface(
@@ -85,21 +61,7 @@ with gr.Blocks() as demo:
85
  outputs="text",
86
  description="chat",
87
  #examples= [[f"\nfriend: λ„ˆλŠ” 꿈이 뭐야? \nyou: "],[f"\nyou: λ„ˆλŠ” 무슨 색을 κ°€μž₯ μ’‹μ•„ν•΄? \nfriend: κΈ€μŽ„ λ„ˆλŠ”? \nyou: "]]
88
- examples= [[f"\nHuman: λ„ˆλŠ” 꿈이 뭐야? \nAssistant: "],[f"\nAssistant: λ„ˆλŠ” 무슨 색을 κ°€μž₯ μ’‹μ•„ν•΄? \nHuman: λ‚˜λŠ” νŒŒλž€μƒ‰μ΄ 쒋더라. λ„ˆλŠ”? \nAssistant: "]]
89
- )
90
-
91
- bb = gr.Interface(
92
- fn=mbti,
93
- inputs="text",
94
- outputs="text",
95
- description="mbti"
96
- )
97
-
98
- cc = gr.Interface(
99
- fn=yn,
100
- inputs="text",
101
- outputs="text",
102
- description="yn",
103
- examples= [[f"그래라"],[f"별둠데?"]]
104
  )
 
105
  demo.queue(max_size=32).launch(enable_queue=True)
 
3
  import inspect
4
  from gradio import routes
5
  from typing import List, Type
 
6
 
7
  import requests, os, re, asyncio
8
 
9
 
10
  loop = asyncio.get_event_loop()
11
+ gradio_client = GrClient('https://ldhldh-demo.hf.space/')
 
12
  # Monkey patch
13
  def get_types(cls_set: List[Type], component: str):
14
  docset = []
 
28
  return docset, types
29
  routes.get_types = get_types
30
 
 
31
  # App code
 
 
 
 
 
 
 
 
 
 
 
32
  def chat(x):
33
+ x = f"[***λ„ˆλŠ” Assistantμž…λ‹ˆλ‹€. μƒλŒ€μ—κ²Œ λ‹€μ–‘ν•œ μ§ˆλ¬Έμ„ ν•˜λ©° λŒ€ν™”λ₯Ό 이끌고 μžˆμŠ΅λ‹ˆλ‹€. Humanμ—κ²Œ 긍정적이고, κ³΅κ°ν•˜λ©°, μ΅œλŒ€ν•œ 길게 λŒ€λ‹΅ν•΄μ£Όμ„Έμš”***]\nHuman: {x}\n\n###\nAssistant:"
 
 
34
 
 
35
  print("\n___________________\n" + f"{x}")
36
  result = gradio_client.predict(
37
  x,
 
53
 
54
  return output
55
 
 
 
 
 
 
 
 
56
  with gr.Blocks() as demo:
57
  count = 0
58
  aa = gr.Interface(
 
61
  outputs="text",
62
  description="chat",
63
  #examples= [[f"\nfriend: λ„ˆλŠ” 꿈이 뭐야? \nyou: "],[f"\nyou: λ„ˆλŠ” 무슨 색을 κ°€μž₯ μ’‹μ•„ν•΄? \nfriend: κΈ€μŽ„ λ„ˆλŠ”? \nyou: "]]
64
+ examples= [[f"λ„ˆλŠ” 꿈이 뭐야?"],[f"λ„ˆλŠ” 무슨 색을 κ°€μž₯ μ’‹μ•„ν•΄?"]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  )
66
+
67
  demo.queue(max_size=32).launch(enable_queue=True)