willn9 commited on
Commit
2544581
·
verified ·
1 Parent(s): 155ceea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -1,14 +1,10 @@
1
  import os
2
  import gradio as gr
3
- from huggingface_hub import InferenceClient
4
 
5
- # Set up the API key and model for Deepseek
6
  DEEPSEEK_API_KEY = os.getenv("Deepseek_API_Key")
7
- DEEPSEEK_MODEL = "deepseek-chat" # Replace with the correct model name if needed
8
-
9
- # Initialize the Deepseek Inference client
10
- client = InferenceClient(model=DEEPSEEK_MODEL, token=DEEPSEEK_API_KEY)
11
-
12
 
13
  def generate_game(auditory_memory, selective_attention, dichotic_listening, phonemic_awareness, temporal_processing, language_comprehension):
14
  # Craft the prompt for the model
@@ -40,16 +36,25 @@ Be concise and limit your response to 512 tokens or less."""
40
 
41
  try:
42
  # Call the Deepseek API
43
- response = client.chat_completion(
44
- messages=[
 
 
 
 
 
45
  {"role": "system", "content": "You are a helpful and knowledgeable learning disabilities expert with knowledge of Central Auditory Processing Disorder (CAPD)."},
46
  {"role": "user", "content": prompt},
47
  ],
48
- max_tokens=512,
49
- temperature=0.7,
50
- )
 
 
 
 
51
  # Extract the response text
52
- game_advice = response.choices[0].message.content.strip()
53
  except Exception as e:
54
  game_advice = f"An error occurred: {str(e)}"
55
 
@@ -92,9 +97,9 @@ CAPD_Game_app = gr.Interface(
92
  lines=2,
93
  ),
94
  ],
95
- outputs=gr.Textbox(label="Recommended Games"),
96
- title="CAPD Games",
97
- description="This App provides general Ai advice regarding CAPD Games. For best results, visit your audiologist or doctor for proper diagnosis and treatment. Disclaimer: AI can make mistakes. Use with caution and at your own risk!",
98
  )
99
 
100
 
 
1
  import os
2
  import gradio as gr
3
+ import requests
4
 
5
+ # Set up the API key and endpoint for Deepseek
6
  DEEPSEEK_API_KEY = os.getenv("Deepseek_API_Key")
7
+ DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions" # Replace with the actual Deepseek API endpoint
 
 
 
 
8
 
9
  def generate_game(auditory_memory, selective_attention, dichotic_listening, phonemic_awareness, temporal_processing, language_comprehension):
10
  # Craft the prompt for the model
 
36
 
37
  try:
38
  # Call the Deepseek API
39
+ headers = {
40
+ "Authorization": f"Bearer {DEEPSEEK_API_KEY}",
41
+ "Content-Type": "application/json",
42
+ }
43
+ data = {
44
+ "model": "deepseek-chat", # Replace with the correct model name if needed
45
+ "messages": [
46
  {"role": "system", "content": "You are a helpful and knowledgeable learning disabilities expert with knowledge of Central Auditory Processing Disorder (CAPD)."},
47
  {"role": "user", "content": prompt},
48
  ],
49
+ "max_tokens": 512,
50
+ "temperature": 0.7,
51
+ }
52
+ response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)
53
+ response.raise_for_status() # Raise an error for bad status codes
54
+ result = response.json()
55
+
56
  # Extract the response text
57
+ game_advice = result["choices"][0]["message"]["content"].strip()
58
  except Exception as e:
59
  game_advice = f"An error occurred: {str(e)}"
60
 
 
97
  lines=2,
98
  ),
99
  ],
100
+ outputs=gr.Textbox(label="Recommended Games", lines=25),
101
+ title="CAPD Game Recommender on BrainAPT.com",
102
+ description="This app provides general advice regarding CAPD Games. For best results, visit your audiologist or doctor for proper diagnosis and treatment. Disclaimer: AI can make mistakes. Use with caution and at your own risk!",
103
  )
104
 
105