KishoreK commited on
Commit
3946f8e
1 Parent(s): 53610ad

resoved HF_TOKEN error

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -3,11 +3,12 @@
3
  import gradio as gr
4
  import requests
5
  import os
 
6
 
7
  ##Bloom
8
  API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
9
- HF_TOKEN = os.environ["HF_TOKEN"]
10
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
11
 
12
  def translate(prompt_ , from_lang, to_lang, input_prompt = "translate this", seed = 42):
13
 
@@ -33,10 +34,11 @@ def translate(prompt_ , from_lang, to_lang, input_prompt = "translate this", see
33
  "wait_for_model": True,
34
  },
35
  }
36
- response = requests.post(API_URL, headers=headers, json=json_)
37
- output = response.json()
 
38
  output_tmp = output[0]['generated_text']
39
- solution = output_tmp.split(f"\n{to_lang}:")[0]
40
 
41
 
42
  if '\n\n' in solution:
3
  import gradio as gr
4
  import requests
5
  import os
6
+ import json #
7
 
8
  ##Bloom
9
  API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
10
+ # HF_TOKEN = os.environ["HF_TOKEN"]
11
+ # headers = {"Authorization": f"Bearer {HF_TOKEN}"}
12
 
13
  def translate(prompt_ , from_lang, to_lang, input_prompt = "translate this", seed = 42):
14
 
34
  "wait_for_model": True,
35
  },
36
  }
37
+ response = requests.request("POST", API_URL, json=json_) # headers=headers
38
+ # output = response.json()
39
+ output = json.loads(response.content.decode("utf-8"))
40
  output_tmp = output[0]['generated_text']
41
+ solution = output_tmp.split(f"\n{to_lang}:")[0]
42
 
43
 
44
  if '\n\n' in solution: