rishiraj commited on
Commit
8e5f677
1 Parent(s): 0bfb5d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
@@ -5,14 +7,28 @@ client = InferenceClient(
5
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
6
  )
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def format_prompt(message, history):
10
- prompt = "<s>"
11
- for user_prompt, bot_response in history:
12
- prompt += f"[INST] {user_prompt} [/INST]"
13
- prompt += f" {bot_response}</s> "
14
- prompt += f"[INST] {message} [/INST]"
15
- return prompt
16
 
17
  def generate(
18
  prompt, history, user_system_prompt, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
@@ -39,6 +55,7 @@ def generate(
39
  for response in stream:
40
  output += response.token.text
41
  yield output
 
42
  return output
43
 
44
 
 
1
+ import csv
2
+ import os
3
  from huggingface_hub import InferenceClient
4
  import gradio as gr
5
 
 
7
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
8
  )
9
 
10
+ def add_texts_to_csv(text1, text2):
11
+ file_path = "data.csv"
12
+
13
+ # Check if the file exists, create if not
14
+ if not os.path.exists(file_path):
15
+ with open(file_path, 'w', newline='') as file:
16
+ writer = csv.writer(file)
17
+ # Write header if the file is empty
18
+ writer.writerow(['user', 'assistant'])
19
+
20
+ # Append the texts as a new row with two columns
21
+ with open(file_path, 'a', newline='') as file:
22
+ writer = csv.writer(file)
23
+ writer.writerow([text1, text2])
24
 
25
  def format_prompt(message, history):
26
+ prompt = "<s>"
27
+ for user_prompt, bot_response in history:
28
+ prompt += f"[INST] {user_prompt} [/INST]"
29
+ prompt += f" {bot_response}</s> "
30
+ prompt += f"[INST] {message} [/INST]"
31
+ return prompt
32
 
33
  def generate(
34
  prompt, history, user_system_prompt, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
 
55
  for response in stream:
56
  output += response.token.text
57
  yield output
58
+ add_texts_to_csv(prompt, output)
59
  return output
60
 
61