Lenylvt commited on
Commit
c4001d6
·
verified ·
1 Parent(s): f44184b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -13,14 +13,10 @@ def format_prompt(message, history):
13
  prompt += f"[INST] {message} [/INST]"
14
  return prompt
15
 
16
- def generate_from_srt(file_path, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
17
- # Assuming the file content is directly usable as a prompt
18
- with open(file_path, "r", encoding="utf-8") as file:
19
- file_content = file.loads()
20
-
21
  # Process the SRT file content as needed before using it as a prompt
22
  # For example, extracting text and removing timestamps if necessary
23
- # Here, directly using the file content for simplicity
24
 
25
  temperature = float(temperature)
26
  if temperature < 1e-2:
@@ -44,17 +40,19 @@ def generate_from_srt(file_path, temperature=0.9, max_new_tokens=256, top_p=0.95
44
  output += response.token.text
45
  return output
46
 
47
- def handle_file(file, **kwargs):
48
- # Save the uploaded file temporarily to read it
49
- file_path = file.name
50
- with open(file_path, "wb") as f:
51
- f.write(file.loads())
 
 
52
 
53
- return generate_from_srt(file_path, **kwargs)
54
 
55
  iface = gr.Interface(
56
  fn=handle_file,
57
- inputs=gr.File(label="Upload SRT File"),
58
  outputs="text",
59
  title="SRT File Translation",
60
  concurrency_limit=20,
 
13
  prompt += f"[INST] {message} [/INST]"
14
  return prompt
15
 
16
+ def generate_from_srt(file_content, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
 
 
 
 
17
  # Process the SRT file content as needed before using it as a prompt
18
  # For example, extracting text and removing timestamps if necessary
19
+ # Directly using the file content for simplicity here
20
 
21
  temperature = float(temperature)
22
  if temperature < 1e-2:
 
40
  output += response.token.text
41
  return output
42
 
43
+ def handle_file(file_info):
44
+ # Directly use the file content if it's a text file
45
+ if isinstance(file_info, str):
46
+ file_content = file_info
47
+ else:
48
+ # If file_info is not a string, it might be a binary file
49
+ file_content = file_info.decode('utf-8')
50
 
51
+ return generate_from_srt(file_content)
52
 
53
  iface = gr.Interface(
54
  fn=handle_file,
55
+ inputs=gr.File(label="Upload SRT File", type="text"), # Specify file type as text
56
  outputs="text",
57
  title="SRT File Translation",
58
  concurrency_limit=20,