yentinglin commited on
Commit
9aa8f5f
1 Parent(s): 7a3d937

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +27 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,8 +1,20 @@
1
  import os
 
2
  import gradio as gr
3
  from text_generation import Client
4
  from conversation import get_default_conv_template
5
  from transformers import AutoTokenizer
 
 
 
 
 
 
 
 
 
 
 
6
  DESCRIPTION = """
7
  # Language Models for Taiwanese Culture
8
 
@@ -64,7 +76,8 @@ DEFAULT_MAX_NEW_TOKENS = 1024
64
 
65
  max_prompt_length = 4096 - MAX_MAX_NEW_TOKENS - 10
66
 
67
- tokenizer = AutoTokenizer.from_pretrained("yentinglin/Taiwan-LLaMa-v1.0")
 
68
 
69
  with gr.Blocks() as demo:
70
  gr.Markdown(DESCRIPTION)
@@ -152,6 +165,18 @@ with gr.Blocks() as demo:
152
  history[-1][1] += character
153
  yield history
154
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
156
  fn=bot,
157
  inputs=[
@@ -238,4 +263,4 @@ with gr.Blocks() as demo:
238
  gr.Markdown(LICENSE)
239
 
240
  demo.queue(concurrency_count=4, max_size=128)
241
- demo.launch()
 
1
  import os
2
+
3
  import gradio as gr
4
  from text_generation import Client
5
  from conversation import get_default_conv_template
6
  from transformers import AutoTokenizer
7
+ from pymongo import MongoClient
8
+
9
+ DB_NAME = os.getenv("MONGO_DBNAME", "taiwan-llm")
10
+ USER = os.getenv("MONGO_USER")
11
+ PASSWORD = os.getenv("MONGO_PASSWORD")
12
+
13
+ uri = f"mongodb+srv://{USER}:{PASSWORD}@{DB_NAME}.kvwjiok.mongodb.net/?retryWrites=true&w=majority"
14
+ mongo_client = MongoClient(uri)
15
+ db = mongo_client[DB_NAME]
16
+ conversations_collection = db['conversations']
17
+
18
  DESCRIPTION = """
19
  # Language Models for Taiwanese Culture
20
 
 
76
 
77
  max_prompt_length = 4096 - MAX_MAX_NEW_TOKENS - 10
78
 
79
+ model_name = "yentinglin/Taiwan-LLaMa-v1.0"
80
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
81
 
82
  with gr.Blocks() as demo:
83
  gr.Markdown(DESCRIPTION)
 
165
  history[-1][1] += character
166
  yield history
167
 
168
+ # After generating the response, store the conversation history in MongoDB
169
+ conversation_document = {
170
+ "model_name": model_name,
171
+ "history": history,
172
+ "system_prompt": system_prompt,
173
+ "max_new_tokens": max_new_tokens,
174
+ "temperature": temperature,
175
+ "top_p": top_p,
176
+ "top_k": top_k,
177
+ }
178
+ conversations_collection.insert_one(conversation_document)
179
+
180
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
181
  fn=bot,
182
  inputs=[
 
263
  gr.Markdown(LICENSE)
264
 
265
  demo.queue(concurrency_count=4, max_size=128)
266
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  text-generation==0.6.0
2
- transformers==4.31.0
 
 
1
  text-generation==0.6.0
2
+ transformers==4.31.0
3
+ pymongo==4.4.1