anumukhe commited on
Commit
113e451
1 Parent(s): 30fda63

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -77
app.py DELETED
@@ -1,77 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- import os
4
- import json
5
-
6
- API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
7
- headers = {"Authorization": f"Bearer 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"}
8
-
9
- def translate(prompt_ , from_lang, to_lang, input_prompt = "translate this", seed = 42):
10
-
11
-
12
- prompt = f"To say \"{prompt_}\" in {to_lang}, you would say"
13
- print(prompt)
14
- if len(prompt) == 0:
15
- prompt = input_prompt
16
-
17
- json_ = {
18
- "inputs": prompt,
19
- "parameters": {
20
- "top_p": 0.9,
21
- "top_k": 100,
22
- "temperature": 1.1,
23
- "max_new_tokens": 250,
24
- "return_full_text": True,
25
- "do_sample": True,
26
- "num_beams": 3,
27
- "seed": seed,
28
- "repetition_penalty": 3.0,
29
- },
30
- "options": {
31
- "use_cache": True,
32
- "wait_for_model": True,
33
- },
34
- }
35
- response = requests.post(API_URL, headers=headers, json=json_)
36
- print(f"Response is : {response}")
37
- output = json.loads(response.content.decode("utf-8"))#response.json()
38
- print(f"output is : {output}")
39
- #output = json.loads(response.content.decode("utf-8"))
40
- output_tmp = output[0]['generated_text']
41
- print(f"output_tmp is: {output_tmp}")
42
-
43
- solution = output_tmp.split(f"\n{to_lang}:")[0]
44
-
45
-
46
- if '\n\n' in solution:
47
- final_solution = solution.split("\n\n")[0]
48
- else:
49
- final_solution = solution
50
-
51
- return final_solution
52
-
53
- demo = gr.Blocks()
54
-
55
- with demo:
56
- gr.Markdown("<h1><center>Bloom Translation</center></h1>")
57
-
58
- with gr.Row():
59
- from_lang = gr.Dropdown(['English', 'Spanish', 'Hindi' , 'Bangla'],
60
- value='English',
61
- label='select From language : ')
62
- with gr.Row():
63
- to_lang = gr.Dropdown(['English', 'Spanish', 'Hindi'],
64
- value='Hindi',
65
- label= 'select to Language : ')
66
-
67
- input_prompt = gr.Textbox(label="Enter the sentence : ",
68
- value=f"Please write the text here :",
69
- lines=6)
70
-
71
- generated_txt = gr.Textbox(lines=3)
72
-
73
- b1 = gr.Button("translate")
74
- b1.click(translate,inputs=[ input_prompt, from_lang, to_lang], outputs=generated_txt)
75
-
76
- demo.launch(enable_queue=True, debug=True)
77
-