AnaCarolRicci commited on
Commit
21daff1
·
verified ·
1 Parent(s): 4631d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,26 +1,25 @@
1
  import gradio as gr
2
  import requests
 
3
 
4
- # Simulating the API Key as "legal"
5
- API_KEY = 'sk-7ac906276b784f45a9a989aafccef946'
6
 
7
- # Chatbot Function using DeepSeek LLM
 
 
 
 
 
8
  def ielts_chat(user_input, part):
9
  prompt = f"You are an IELTS tutor. Answer the following question in detail as if you were helping a student prepare for the IELTS Speaking test.\n\nPart: {part}\nQuestion: {user_input}\n\nAnswer:"
10
 
11
  response = requests.post(
12
- "https://api.deepseek.com/v1/completions",
13
- headers={"Authorization": f"Bearer {API_KEY}"},
14
- json={
15
- "model": "deepseek-llm",
16
- "prompt": prompt,
17
- "max_tokens": 150,
18
- "temperature": 0.7
19
- }
20
  )
21
 
22
  if response.status_code == 200:
23
- return response.json()['choices'][0]['text'].strip()
24
  else:
25
  return f"Error {response.status_code}: {response.text}"
26
 
@@ -33,8 +32,7 @@ iface = gr.Interface(
33
  ],
34
  outputs="text",
35
  title="IELTS Speaking Practice Bot",
36
- description="Ask a question related to IELTS Speaking, and the bot will respond as if it were an IELTS tutor using AI-generated responses from DeepSeek LLM."
37
  )
38
 
39
  iface.launch()
40
-
 
1
  import gradio as gr
2
  import requests
3
+ import os
4
 
 
 
5
 
6
+
7
+ # Hugging Face Inference API Token
8
+ API_URL = "https://api-inference.huggingface.co/models/gpt2"
9
+ API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN") # Replace with your Hugging Face API token
10
+
11
+ # Chatbot Function using Hugging Face Inference API
12
  def ielts_chat(user_input, part):
13
  prompt = f"You are an IELTS tutor. Answer the following question in detail as if you were helping a student prepare for the IELTS Speaking test.\n\nPart: {part}\nQuestion: {user_input}\n\nAnswer:"
14
 
15
  response = requests.post(
16
+ API_URL,
17
+ headers={"Authorization": f"Bearer {API_TOKEN}"},
18
+ json={"inputs": prompt}
 
 
 
 
 
19
  )
20
 
21
  if response.status_code == 200:
22
+ return response.json()[0]['generated_text'].strip()
23
  else:
24
  return f"Error {response.status_code}: {response.text}"
25
 
 
32
  ],
33
  outputs="text",
34
  title="IELTS Speaking Practice Bot",
35
+ description="Ask a question related to IELTS Speaking, and the bot will respond as if it were an IELTS tutor using AI-generated responses from Hugging Face's GPT-2 model."
36
  )
37
 
38
  iface.launch()