Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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(
|
| 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"
|
| 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)
|