usmanyousaf commited on
Commit
d73cd3f
·
verified ·
1 Parent(s): aab3cd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -55,11 +55,9 @@ async def check_grammar(transcription: str = Form(...), language: str = Form(...
55
  # Grammar check
56
  grammar_prompt = (
57
  f"Briefly check the grammar of the following text in {language}: {transcription}. "
58
- "Identify any word that does not belong to the selected language and flag it. "
59
- "Based on the number of incorrect words also check the grammar deeply and carefully. "
60
- "Provide a score from 1 to 10 based on the grammar accuracy, reducing points for incorrect words and make sure to output the score on a new line after two line breaks like 'SCORE='."
61
  )
62
-
63
  grammar_check_response = client.chat.completions.create(
64
  model="llama3-groq-70b-8192-tool-use-preview",
65
  messages=[{"role": "user", "content": grammar_prompt}]
@@ -69,9 +67,8 @@ async def check_grammar(transcription: str = Form(...), language: str = Form(...
69
  # Vocabulary check
70
  vocabulary_prompt = (
71
  f"Check the vocabulary accuracy of the following text in {language}: {transcription}. "
72
- "Identify any word that does not belong to the selected language and flag it. "
73
- "Based on the number of incorrect words also check the grammar deeply and carefully. "
74
- "Provide a score from 1 to 10 based on the vocabulary accuracy reducing points for incorrect words and make sure to output the score on a new line after two line breaks like 'SCORE='."
75
  )
76
 
77
  vocabulary_check_response = client.chat.completions.create(
@@ -96,22 +93,21 @@ async def check_grammar(transcription: str = Form(...), language: str = Form(...
96
 
97
 
98
  def calculate_score(feedback: str) -> int:
99
- """
100
- Calculate score based on feedback content.
101
  This function searches for the keyword 'SCORE=' or similar variations
102
  (SCORE:, score:, etc.) and extracts the score value.
103
  """
 
104
  import re
105
  match = re.search(r'(SCORE=|score=|SCORE:|score:|SCORE = )\s*(\d+)', feedback)
106
 
107
  if match:
 
108
  return int(match.group(2))
109
 
110
- return 0 # Return default score of 0 if no score is found
111
-
112
-
113
- # Run the FastAPI app (only needed for local development)
114
- # Run the FastAPI app (needed for local development)
115
  if __name__ == "__main__":
116
  import uvicorn
117
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
55
  # Grammar check
56
  grammar_prompt = (
57
  f"Briefly check the grammar of the following text in {language}: {transcription}. "
58
+ "Identify any word that does not belong to the selected language and flag it. Based on the number of incorrect words also check the grammer deeply and carefully "
59
+ "Provide a score from 1 to 10 based on the grammar accuracy, reducing points for incorrect words and make sure to output the score on a new line after two line break like ""SCORE=""."
 
60
  )
 
61
  grammar_check_response = client.chat.completions.create(
62
  model="llama3-groq-70b-8192-tool-use-preview",
63
  messages=[{"role": "user", "content": grammar_prompt}]
 
67
  # Vocabulary check
68
  vocabulary_prompt = (
69
  f"Check the vocabulary accuracy of the following text in {language}: {transcription}. "
70
+ "Identify any word that does not belong to the selected language and flag it. Based on the number of incorrect words also check the grammer deeply and carefully "
71
+ "provide a score from 1 to 10,based on the vocabulary accuracy reducing points for incorrect words and make sure to output the score on a new line after two line break like ""SCORE=""."
 
72
  )
73
 
74
  vocabulary_check_response = client.chat.completions.create(
 
93
 
94
 
95
  def calculate_score(feedback: str) -> int:
96
+ """
97
+ Calculate score based on feedback content.
98
  This function searches for the keyword 'SCORE=' or similar variations
99
  (SCORE:, score:, etc.) and extracts the score value.
100
  """
101
+ # Look for 'SCORE=' or similar variations and extract the score using a regular expression
102
  import re
103
  match = re.search(r'(SCORE=|score=|SCORE:|score:|SCORE = )\s*(\d+)', feedback)
104
 
105
  if match:
106
+ # Extract and return the score as an integer
107
  return int(match.group(2))
108
 
109
+ # Return a default score of 0 if no score is found in the feedback
110
+ return 0
 
 
 
111
  if __name__ == "__main__":
112
  import uvicorn
113
  uvicorn.run(app, host="0.0.0.0", port=7860)