deepsync commited on
Commit
d7e36aa
1 Parent(s): e79aa9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -2
app.py CHANGED
@@ -82,12 +82,64 @@ def dubpro_english_transliteration(text):
82
  return response_content
83
 
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  with gr.Blocks() as demo:
86
  gr.Markdown("English Transliteration Tool")
87
  with gr.Row():
88
  input_text = gr.Textbox(label="Input text", info="Please enter English text.")
89
  output_text = gr.Textbox(label="Output text")
90
- submit = gr.Button("Submit")
91
- submit.click(dubpro_english_transliteration, input_text, output_text)
 
 
 
 
 
 
 
 
92
 
93
  demo.launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
 
82
  return response_content
83
 
84
 
85
+ def generate_rephrases_gemini(text):
86
+ API_URL = os.environ.get("GEMINI_FINETUNED_HINDI_ENG_API")
87
+ BEARER_TOKEN = get_google_token()
88
+ headers = {
89
+ "Authorization": f"Bearer {BEARER_TOKEN}",
90
+ "Content-Type": "application/json",
91
+ }
92
+ payload = {
93
+ "contents": [
94
+ {
95
+ "parts": [
96
+ {
97
+ "text": "You are a language expert. Return rephrases of the provided text without any loss in information keeping the same tone and style of text, so that it takes a little less time when generating audio. Return only the outputs in a new line."
98
+ },
99
+ {
100
+ "text": f"input: {text}"
101
+ },
102
+ {
103
+ "text": f"output: "
104
+ }
105
+ ],
106
+ "role": "user",
107
+ }
108
+ ],
109
+ "generationConfig": {
110
+ "maxOutputTokens": 8192,
111
+ "temperature": 0.85,
112
+ "candidateCount": 1,
113
+ },
114
+ "safetySettings": [
115
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
116
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
117
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
118
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
119
+ ],
120
+ }
121
+ result = requests.post(url=API_URL, headers=headers, json=payload)
122
+ response = result.json()
123
+ output_text = response["candidates"][0]["content"]["parts"][0]["text"]
124
+
125
+ texts = list(map(lambda x: x.replace("-", "").strip(), output_text.split("\n")))
126
+ return texts
127
+
128
+
129
  with gr.Blocks() as demo:
130
  gr.Markdown("English Transliteration Tool")
131
  with gr.Row():
132
  input_text = gr.Textbox(label="Input text", info="Please enter English text.")
133
  output_text = gr.Textbox(label="Output text")
134
+ transliterate = gr.Button("Submit")
135
+ transliterate.click(dubpro_english_transliteration, input_text, output_text)
136
+
137
+ gr.Markdown("Rephraser Tool")
138
+ with gr.Row():
139
+ rephrase_text = gr.Textbox(label="Input text", info="Please enter text.")
140
+ rephrased_text = gr.Textbox(label="Output text")
141
+ rephrase = gr.Button("Submit")
142
+ rephrase.click(generate_rephrases_gemini, rephrase_text, rephrased_text)
143
+
144
 
145
  demo.launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))