XMMR12 commited on
Commit
d563681
·
verified ·
1 Parent(s): 707f6fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from typing import List, Tuple, Dict, Any, Generator
2
  import sqlite3
3
  import urllib
4
- #import requests
5
  import os
6
  import gradio as gr
7
  import time
@@ -260,8 +260,12 @@ def analyze_symptoms_from_text_ai(text_input: str) -> str:
260
  )
261
 
262
  # Extract and clean the response
263
- symptoms_csv = response.choices.message.content.strip()
264
- return symptoms_csv
 
 
 
 
265
 
266
  except Exception as e:
267
  print(f"Error analyzing symptoms: {str(e)}")
@@ -518,7 +522,7 @@ class BotanistAssistant:
518
  top_p=0.9,
519
  extra_body={"top_k": 50},
520
  messages=messages)
521
- return response.choices.message.content
522
 
523
  except Exception as e:
524
  print(f"Error: {str(e)}")
@@ -572,8 +576,12 @@ class BotanistAssistant:
572
  #yield treatment_response # First yield the treatment info
573
 
574
  # Stream additional assistant responses if available
575
- if api_response and api_response.choices:
576
- yield api_response.choices.message.content
 
 
 
 
577
 
578
  def create_app(api_endpoint: str = "https://api.studio.nebius.com/v1/") -> gr.Blocks:
579
  """Creates and configures the Gradio interface."""
 
1
  from typing import List, Tuple, Dict, Any, Generator
2
  import sqlite3
3
  import urllib
4
+ import requests
5
  import os
6
  import gradio as gr
7
  import time
 
260
  )
261
 
262
  # Extract and clean the response
263
+ try:
264
+ symptoms_csv = response.choices.message.content.strip()
265
+ return symptoms_csv
266
+ except Exception as e:
267
+ print ("Error:",e,"\nType 'response': ",type(response),"\n",response)
268
+
269
 
270
  except Exception as e:
271
  print(f"Error analyzing symptoms: {str(e)}")
 
522
  top_p=0.9,
523
  extra_body={"top_k": 50},
524
  messages=messages)
525
+ return response.to_json()
526
 
527
  except Exception as e:
528
  print(f"Error: {str(e)}")
 
576
  #yield treatment_response # First yield the treatment info
577
 
578
  # Stream additional assistant responses if available
579
+ if "choices" in api_response:
580
+ for choice in api_response["choices"]:
581
+ if "message" in choice and "content" in choice["message"]:
582
+ yield choice["message"]["content"]
583
+
584
+
585
 
586
  def create_app(api_endpoint: str = "https://api.studio.nebius.com/v1/") -> gr.Blocks:
587
  """Creates and configures the Gradio interface."""