ldhldh commited on
Commit
8c634b2
1 Parent(s): 164a52e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -16
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- from gradio_client import Client as GrClient
3
  from gradio import routes
4
  from typing import List, Type
5
 
@@ -29,32 +28,70 @@ def get_types(cls_set: List[Type], component: str):
29
  return docset, types
30
  routes.get_types = get_types
31
 
32
- history = dict()
 
33
 
34
 
35
- def predict(user_id, gender, age):
36
- # 추천 해서 반환
37
- movie = "추천 영화"
38
- return f"{movie}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- def add(user_id, movie):
41
- if not user_id in history:
42
- history[user_id] = []
43
- history[user_id].append(movie)
 
44
  return "ok"
45
 
46
  with gr.Blocks() as demo:
47
  count = 0
48
  aa = gr.Interface(
49
- fn=predict,
50
- inputs=["text", "text", "text"],
51
  outputs="text",
52
- description="추천",
53
  )
54
  bb = gr.Interface(
55
- fn=add,
56
  inputs=["text", "text"],
57
  outputs="text",
58
- description="시청기록 추가",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  )
60
- demo.queue(max_size=32).launch(enable_queue=True)
 
1
  import gradio as gr
 
2
  from gradio import routes
3
  from typing import List, Type
4
 
 
28
  return docset, types
29
  routes.get_types = get_types
30
 
31
+ user_data = dict()
32
+ chat_history = []
33
 
34
 
35
+ def register(id, pw):
36
+ if not id in user_data:
37
+ user_data[id] = pw
38
+ return "ok"
39
+ else:
40
+ return "fail"
41
+
42
+ def login(id, pw):
43
+ if not id in user_data:
44
+ return "fail"
45
+ else:
46
+ if user_data[id] != pw:
47
+ return "fail"
48
+ else:
49
+ return "ok"
50
+
51
+ def chat(name, text):
52
+ if not name in user_data:
53
+ return "no id"
54
+ else:
55
+ chat_history.append({"name": name, "text":text})
56
+ return "ok"
57
 
58
+ def get_data():
59
+ return chat_history
60
+
61
+ def clear_data():
62
+ chat_history = []
63
  return "ok"
64
 
65
  with gr.Blocks() as demo:
66
  count = 0
67
  aa = gr.Interface(
68
+ fn=chat,
69
+ inputs=["text", "text"],
70
  outputs="text",
71
+ description="chat",
72
  )
73
  bb = gr.Interface(
74
+ fn=login,
75
  inputs=["text", "text"],
76
  outputs="text",
77
+ description="login",
78
+ )
79
+ cc = gr.Interface(
80
+ fn=register,
81
+ inputs=["text", "text"],
82
+ outputs="text",
83
+ description="register",
84
+ )
85
+ dd = gr.Interface(
86
+ fn=get_data,
87
+ inputs=[],
88
+ outputs="text",
89
+ description="get_data",
90
+ )
91
+ gg = gr.Interface(
92
+ fn=clear_data,
93
+ inputs=[],
94
+ outputs="text",
95
+ description="clear_data",
96
  )
97
+ demo.queue(max_size=32).launch()