deepsync commited on
Commit
8d8cdf7
1 Parent(s): 60eadfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -82,17 +82,21 @@ def dubpro_english_transliteration(text):
82
  return response_content
83
 
84
 
85
- def generate_rephrases_gemini(text, language):
86
  API_URL = os.environ.get("GEMINI_REPHRASER_API")
87
  BEARER_TOKEN = get_google_token()
88
  headers = {
89
  "Authorization": f"Bearer {BEARER_TOKEN}",
90
  "Content-Type": "application/json",
91
  }
 
 
 
 
92
  if language == "English":
93
- prompt = "You are an English and Hindi language expert, please rephrase a sentence that has been translated from Hindi to English so that it takes little less time to speak."
94
  elif language == "Hindi":
95
- prompt = "You are a hindi language expert please rephrase the below line without summary so that it takes little less time to speak in hinglish manner."
96
 
97
  payload = {
98
  "contents": [
@@ -128,7 +132,10 @@ def generate_rephrases_gemini(text, language):
128
  output_text = response["candidates"][0]["content"]["parts"][0]["text"]
129
 
130
  texts = list(map(lambda x: x.replace("-", "").strip(), output_text.split("\n")))
131
- return "\n".join(texts)
 
 
 
132
 
133
 
134
  with gr.Blocks() as demo:
@@ -143,9 +150,12 @@ with gr.Blocks() as demo:
143
  with gr.Row():
144
  rephrase_text = gr.Textbox(label="Input text", info="Please enter text.")
145
  language = gr.Dropdown(["English", "Hindi"], value="Hindi")
 
 
 
146
  rephrased_text = gr.Textbox(label="Output text")
147
  rephrase = gr.Button("Submit")
148
- rephrase.click(generate_rephrases_gemini, [rephrase_text, language], rephrased_text)
149
 
150
 
151
  demo.launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
 
82
  return response_content
83
 
84
 
85
+ def generate_rephrases_gemini(text, language, problem):
86
  API_URL = os.environ.get("GEMINI_REPHRASER_API")
87
  BEARER_TOKEN = get_google_token()
88
  headers = {
89
  "Authorization": f"Bearer {BEARER_TOKEN}",
90
  "Content-Type": "application/json",
91
  }
92
+ if problem == "Gap":
93
+ speak = "more"
94
+ else:
95
+ speak = "less"
96
  if language == "English":
97
+ prompt = f"You are an English and Hindi language expert, please rephrase a sentence that has been translated from Hindi to English so that it takes little {speak} time to speak."
98
  elif language == "Hindi":
99
+ prompt = f"You are a hindi language expert please rephrase the below line without summary so that it takes little {speak} time to speak in hinglish manner."
100
 
101
  payload = {
102
  "contents": [
 
132
  output_text = response["candidates"][0]["content"]["parts"][0]["text"]
133
 
134
  texts = list(map(lambda x: x.replace("-", "").strip(), output_text.split("\n")))
135
+
136
+ wc = f"Original Word Count: {len(text.split())}\nRephrased Word Count: {len(texts.split())}"
137
+
138
+ return "\n".join(texts), wc
139
 
140
 
141
  with gr.Blocks() as demo:
 
150
  with gr.Row():
151
  rephrase_text = gr.Textbox(label="Input text", info="Please enter text.")
152
  language = gr.Dropdown(["English", "Hindi"], value="Hindi")
153
+ solving_for = gr.Dropdown(["Gap", "Overflow"], value="Overflow", label="Solving for:")
154
+ with gr.Row():
155
+ word_count = gr.Textbox(label="Word count")
156
  rephrased_text = gr.Textbox(label="Output text")
157
  rephrase = gr.Button("Submit")
158
+ rephrase.click(generate_rephrases_gemini, [rephrase_text, language, solving_for], [rephrased_text, word_count])
159
 
160
 
161
  demo.launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))