mayankchugh-learning commited on
Commit
4cd520b
1 Parent(s): 73cf229

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -3,6 +3,28 @@ from transformers import pipeline
3
  import torch
4
  import gradio as gr
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
7
 
8
  # model_path = "Model/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"
@@ -25,6 +47,17 @@ text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6",
25
 
26
  def summary(input):
27
  output = text_summary(input)
 
 
 
 
 
 
 
 
 
 
 
28
  return output[0]['summary_text']
29
 
30
  gr.close_all()
 
3
  import torch
4
  import gradio as gr
5
 
6
+ from huggingface_hub import CommitScheduler
7
+ from pathlib import Path
8
+
9
+ import os
10
+ import uuid
11
+ import joblib
12
+ import json
13
+
14
+ # Prepare the logging functionality
15
+
16
+ log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
17
+ log_folder = log_file.parent
18
+
19
+ scheduler = CommitScheduler(
20
+ repo_id="text-summarization-logs",
21
+ repo_type="dataset",
22
+ folder_path=log_folder,
23
+ path_in_repo="data",
24
+ every=2
25
+ )
26
+
27
+
28
  text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
29
 
30
  # model_path = "Model/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"
 
47
 
48
  def summary(input):
49
  output = text_summary(input)
50
+
51
+ with scheduler.lock:
52
+ with log_file.open("a") as f:
53
+ f.write(json.dumps(
54
+ {
55
+ 'Input Text': input,
56
+ 'Summary':output[0]['summary_text']
57
+ }
58
+ ))
59
+ f.write("\n")
60
+
61
  return output[0]['summary_text']
62
 
63
  gr.close_all()