Julien Matuszak commited on
Commit
a64a73d
·
verified ·
1 Parent(s): f51d6e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -26
app.py CHANGED
@@ -9,36 +9,24 @@ import requests
9
  nlp = spacy.load("en_core_web_sm") # Use "en_core_web_trf" if more accuracy is needed
10
  spell_checker = pipeline("text2text-generation", model="oliverguhr/spelling-correction-english-base")
11
 
12
- def preprocess_and_forward(text: str) -> str:
 
 
 
 
13
  processed_text, preprocessing_results = preprocess_text(text)
14
 
15
- try:
16
- # Forward preprocessed text to context detection
17
- context_response = requests.post(
18
- "https://api.gradio.app/v2/Frenchizer/space_17/predict",
19
- json={"data": [processed_text]}
20
- ).json()
21
-
22
- if "error" in context_response:
23
- return json.dumps({
24
- "error": "Context detection failed",
25
- "preprocessing_results": preprocessing_results
26
- })
27
-
28
- context = context_response["data"][0]
29
-
30
- # Return preprocessing and detected context
31
- result = {
32
- "preprocessing": preprocessing_results,
33
- "context": context
34
- }
35
- return json.dumps(result)
36
 
 
 
 
 
37
  except Exception as e:
38
- return json.dumps({
39
- "error": str(e),
40
- "preprocessing_results": preprocessing_results
41
- })
42
 
43
  def preprocess_text(text: str):
44
  result = {
 
9
  nlp = spacy.load("en_core_web_sm") # Use "en_core_web_trf" if more accuracy is needed
10
  spell_checker = pipeline("text2text-generation", model="oliverguhr/spelling-correction-english-base")
11
 
12
+ def preprocess_and_forward(text: str) -> dict:
13
+ """
14
+ Processes the input text and forwards it to the Gradio client for space_17.
15
+ """
16
+ # Preprocess the text
17
  processed_text, preprocessing_results = preprocess_text(text)
18
 
19
+ # Instantiate the Gradio Client for space_17
20
+ client = gr.Client("Frenchizer/space_17")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ # Forward preprocessed text to the Gradio client for space_17
23
+ try:
24
+ context_response = client.predict(processed_text)
25
+ preprocessing_results["context_response"] = context_response
26
  except Exception as e:
27
+ preprocessing_results["context_error"] = str(e)
28
+
29
+ return preprocessing_results
 
30
 
31
  def preprocess_text(text: str):
32
  result = {