Dhahlan2000 commited on
Commit
2b513e8
1 Parent(s): b1333f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -114,18 +114,9 @@ def query(payload):
114
  response = requests.post(API_URL, headers=headers, json=payload)
115
  return response.json()
116
 
117
- # def conversation_predict(text):
118
- # return interface([text])[0]
119
-
120
- def ai_predicted(user_input):
121
- if user_input.lower() == 'exit':
122
- return "Goodbye!"
123
-
124
- user_input = translate_Singlish_to_sinhala(user_input)
125
- user_input = transliterate_to_sinhala(user_input)
126
- user_input = translate_sinhala_to_english(user_input)
127
  response_json = query({
128
- "inputs": f"{user_input}",
129
  })
130
  if 'generated_text' in response_json[0]:
131
  ai_response = response_json[0]['generated_text']
@@ -133,11 +124,30 @@ def ai_predicted(user_input):
133
  ai_response = response_json[0]['text']
134
  else:
135
  ai_response = response_json[0]
136
- # ai_response = conversation_predict(user_input)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  # ai_response_lines = ai_response.split("</s>")
 
138
 
139
  response = translate_english_to_sinhala(ai_response)
140
  response = transliterate_from_sinhala(response)
 
 
141
  return response
142
 
143
  # Gradio Interface
 
114
  response = requests.post(API_URL, headers=headers, json=payload)
115
  return response.json()
116
 
117
+ def conversation_predict(text):
 
 
 
 
 
 
 
 
 
118
  response_json = query({
119
+ "inputs": f"{text}",
120
  })
121
  if 'generated_text' in response_json[0]:
122
  ai_response = response_json[0]['generated_text']
 
124
  ai_response = response_json[0]['text']
125
  else:
126
  ai_response = response_json[0]
127
+
128
+ return ai_response
129
+
130
+ def ai_predicted(user_input):
131
+ if user_input.lower() == 'exit':
132
+ print("Goodbye!")
133
+ break
134
+
135
+ user_input = translate_Singlish_to_sinhala(user_input)
136
+ user_input = transliterate_to_sinhala(user_input)
137
+ user_input = translate_sinhala_to_english(user_input)
138
+ print("You(english):", user_input,"\n")
139
+
140
+ # Get AI response
141
+ ai_response = conversation_predict(user_input)
142
+
143
+ # Split the AI response into separate lines
144
  # ai_response_lines = ai_response.split("</s>")
145
+ print("AI(English):", ai_response,"\n")
146
 
147
  response = translate_english_to_sinhala(ai_response)
148
  response = transliterate_from_sinhala(response)
149
+ print(response)
150
+
151
  return response
152
 
153
  # Gradio Interface