Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines345667891012131112131413 unmodified lines282930333135363738394041424344453247484933345135363715 unmodified lines535455737475767778795657582 unmodified lines616263888990919293949596979899100101102103646566672 unmodified linesimport inspectfrom gradio import routesfrom typing import List, Typefrom aiogoogletrans import Translator
import requests, os, re, asyncio
loop = asyncio.get_event_loop()gradio_client = GrClient(os.environ.get('GrClient_url2'))translator = Translator()gradio_client = GrClient('https://ldhldh-demo.hf.space/')# Monkey patchdef get_types(cls_set: List[Type], component: str): docset = []13 unmodified lines return docset, typesroutes.get_types = get_types
# App codedef mbti(x): t = loop.run_until_complete(translator.translate(x, src='ko', dest='en')) str_trans = re.sub('[-=+,#/\?:^.@*\"β»~γ!γβ|\(\)\[\]`\'β¦γ\β\β\βΒ·]', '', t.text) result = gradio_client.predict( str_trans, # str representing input in 'User input' Textbox component fn_index=2 ) r = sorted(eval(result), key=lambda x : x['score'], reverse=True) return r
def chat(x): x = f"[***λλ Assistantμ
λλ€. μλμκ² λ€μν μ§λ¬Έμ νλ©° λνλ₯Ό μ΄λκ³ μμ΅λλ€. Humanμκ² κΈμ μ μ΄κ³ , 곡κ°νλ©°, μ΅λν κΈΈκ² λλ΅ν΄μ£ΌμΈμ***] {x}" x = x.replace('friend','Human').replace('you','Assistant') x_list = x.rsplit('\n',1) x = f"[***λλ Assistantμ
λλ€. μλμκ² λ€μν μ§λ¬Έμ νλ©° λνλ₯Ό μ΄λκ³ μμ΅λλ€. Humanμκ² κΈμ μ μ΄κ³ , 곡κ°νλ©°, μ΅λν κΈΈκ² λλ΅ν΄μ£ΌμΈμ***]\nHuman: {x}\n\n###\nAssistant:"
x = x_list[0]+"\n\n### \n"+x_list[1] print("\n___________________\n" + f"{x}") result = gradio_client.predict( x,15 unmodified lines
return output
def yn(x): result = gradio_client.predict( x, # str representing input in 'User input' Textbox component fn_index=1 ) return result
with gr.Blocks() as demo: count = 0 aa = gr.Interface(2 unmodified lines outputs="text", description="chat", #examples= [[f"\nfriend: λλ κΏμ΄ λμΌ? \nyou: "],[f"\nyou: λλ λ¬΄μ¨ μμ κ°μ₯ μ’μν΄? \nfriend: κΈμ λλ? \nyou: "]] examples= [[f"\nHuman: λλ κΏμ΄ λμΌ? \nAssistant: "],[f"\nAssistant: λλ λ¬΄μ¨ μμ κ°μ₯ μ’μν΄? \nHuman: λλ νλμμ΄ μ’λλΌ. λλ? \nAssistant: "]] ) bb = gr.Interface( fn=mbti, inputs="text", outputs="text", description="mbti" ) cc = gr.Interface( fn=yn, inputs="text", outputs="text", description="yn", examples= [[f"κ·ΈλλΌ"],[f"λ³λ‘ λ°?"]] examples= [[f"λλ κΏμ΄ λμΌ?"],[f"λλ λ¬΄μ¨ μμ κ°μ₯ μ’μν΄?"]] )
demo.queue(max_size=32).launch(enable_queue=True) app.py+4-42