|
import gradio as gr |
|
from gradio_client import Client as GrClient |
|
import inspect |
|
from gradio import routes |
|
from typing import List, Type |
|
|
|
import requests, os, re, asyncio |
|
|
|
|
|
loop = asyncio.get_event_loop() |
|
gradio_client = GrClient('https://ldhldh-demo.hf.space/') |
|
|
|
def get_types(cls_set: List[Type], component: str): |
|
docset = [] |
|
types = [] |
|
if component == "input": |
|
for cls in cls_set: |
|
doc = inspect.getdoc(cls) |
|
doc_lines = doc.split("\n") |
|
docset.append(doc_lines[1].split(":")[-1]) |
|
types.append(doc_lines[1].split(")")[0].split("(")[-1]) |
|
else: |
|
for cls in cls_set: |
|
doc = inspect.getdoc(cls) |
|
doc_lines = doc.split("\n") |
|
docset.append(doc_lines[-1].split(":")[-1]) |
|
types.append(doc_lines[-1].split(")")[0].split("(")[-1]) |
|
return docset, types |
|
routes.get_types = get_types |
|
|
|
|
|
def chat(x): |
|
x = f"[***λλ Assistantμ
λλ€. μλμκ² λ€μν μ§λ¬Έμ νλ©° λνλ₯Ό μ΄λκ³ μμ΅λλ€. Humanμκ² κΈμ μ μ΄κ³ , 곡κ°νλ©°, μ΅λν κΈΈκ² λλ΅ν΄μ£ΌμΈμ***]\nHuman: {x}\n\n###\nAssistant:" |
|
|
|
print("\n___________________\n" + f"{x}") |
|
|
|
result = gradio_client.predict( |
|
x, |
|
|
|
0.91, |
|
10, |
|
0.65, |
|
20, |
|
1.2, |
|
fn_index=0 |
|
) |
|
result = str(result) |
|
output = result[len(x.rsplit(':', 1)[0])+2:] |
|
output = re.sub('νν','γ
γ
', output) |
|
output = output.split('λ')[0] |
|
output = output.split('endoftext')[0] |
|
output = re.sub('[=+#/\:@*\"β»γγβ|\\\<\>\(\)\[\]`\'β¦γ\β\β\βΒ·]', '', output) |
|
|
|
|
|
return output |
|
|
|
with gr.Blocks() as demo: |
|
count = 0 |
|
aa = gr.Interface( |
|
fn=chat, |
|
inputs="text", |
|
outputs="text", |
|
description="chat", |
|
|
|
examples= [[f"λλ κΏμ΄ λμΌ?"],[f"λλ λ¬΄μ¨ μμ κ°μ₯ μ’μν΄?"]] |
|
) |
|
|
|
demo.queue(max_size=32).launch(enable_queue=True) |