Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +1 -1
- interface_utils.py +50 -0
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from
|
| 4 |
|
| 5 |
maxim = 'quantity'
|
| 6 |
submaxims = ["The response provides a sufficient amount of information.",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from interface_utils import *
|
| 4 |
|
| 5 |
maxim = 'quantity'
|
| 6 |
submaxims = ["The response provides a sufficient amount of information.",
|
interface_utils.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import numpy as np
|
| 3 |
+
import random
|
| 4 |
+
import uuid
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def load_from_jsonl(filename, n=np.inf):
|
| 8 |
+
data = []
|
| 9 |
+
with open(filename, 'r') as file:
|
| 10 |
+
for i, line in enumerate(file):
|
| 11 |
+
if i >= n: # stop after reading n lines
|
| 12 |
+
break
|
| 13 |
+
data.append(json.loads(line))
|
| 14 |
+
return data
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def append_id(conversations_no_id):
|
| 18 |
+
conversations = []
|
| 19 |
+
for conversation in conversations_no_id:
|
| 20 |
+
conversations.append({
|
| 21 |
+
'conv_id': uuid.uuid4().hex,
|
| 22 |
+
'transcript': conversation['transcript']
|
| 23 |
+
})
|
| 24 |
+
return conversations
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def save_to_jsonl(data, filename):
|
| 28 |
+
with open(filename, 'w') as file:
|
| 29 |
+
for item in data:
|
| 30 |
+
json_line = json.dumps(item)
|
| 31 |
+
file.write(json_line + '\n')
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def get_conversation(conversation_data):
|
| 35 |
+
conv = random.choice(conversation_data)
|
| 36 |
+
return conv
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def pad_transcript(transcript, max_length):
|
| 40 |
+
padding_count = max_length - len(transcript)
|
| 41 |
+
if padding_count > 0:
|
| 42 |
+
for _ in range(padding_count):
|
| 43 |
+
transcript.append({'speaker': '', 'response': ''})
|
| 44 |
+
return transcript
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_last_response(transcript):
|
| 48 |
+
for turn in reversed(transcript):
|
| 49 |
+
if turn['speaker'] and turn['response']:
|
| 50 |
+
return turn['response']
|