Angelawork commited on
Commit
f01316a
·
1 Parent(s): 4563ea0

helper functions

Browse files
Files changed (1) hide show
  1. utility.py +33 -0
utility.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import urllib.request
3
+ import gradio as gr
4
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
5
+ import huggingface_hub
6
+ import re
7
+ from transformers import AutoTokenizer, AutoModelForCausalLM
8
+ import torch
9
+ import time
10
+ import transformers
11
+ import requests
12
+ import globals
13
+
14
+ def fetch_model(url, filename):
15
+ if not os.path.isfile(filename):
16
+ urllib.request.urlretrieve(url, filename)
17
+ print("File downloaded successfully.")
18
+ else:
19
+ print("File already exists.")
20
+
21
+ def api_query(API_URL, headers, payload):
22
+ response = requests.post(API_URL, headers=headers, json=payload)
23
+ return response.json()
24
+
25
+ def post_process(model_output,input):
26
+ start_pos = model_output.find(input)
27
+ if start_pos != -1:
28
+ answer = model_output[start_pos + len(input):].strip()
29
+ else:
30
+ answer = model_output
31
+ print("'Literal meaning:' not found in the text.")
32
+ answer.replace("\n", "")
33
+ return answer