Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,22 +16,7 @@ class RequestBody(BaseModel):
|
|
| 16 |
@app.post("/api/v1")
|
| 17 |
async def generate_response(request_body: RequestBody):
|
| 18 |
prompt = request_body.prompt
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return all('а' <= char <= 'я' or 'А' <= char <= 'Я' for char in word)
|
| 22 |
-
|
| 23 |
-
def detect_russian_text(text):
|
| 24 |
-
words = re.findall(r'\b\w+\b', text)
|
| 25 |
-
if not words:
|
| 26 |
-
return False
|
| 27 |
-
russian_word_count = sum(1 for word in words if is_russian_word(word))
|
| 28 |
-
russian_ratio = russian_word_count / len(words)
|
| 29 |
-
return russian_ratio > 0.5
|
| 30 |
-
|
| 31 |
-
if detect_russian_text(prompt):
|
| 32 |
-
try:
|
| 33 |
-
all_chunk = GoogleTranslator(source='ru', target='en').translate(prompt)
|
| 34 |
-
except:
|
| 35 |
-
all_chunk = prompt
|
| 36 |
|
| 37 |
return {"response": all_chunk}
|
|
|
|
| 16 |
@app.post("/api/v1")
|
| 17 |
async def generate_response(request_body: RequestBody):
|
| 18 |
prompt = request_body.prompt
|
| 19 |
+
|
| 20 |
+
all_chunk = GoogleTranslator(source='ru', target='en').translate(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
return {"response": all_chunk}
|