pytzen commited on
Commit
6b3fef0
1 Parent(s): 86692fd

feature: docs

Browse files
Files changed (2) hide show
  1. app/index.html +38 -10
  2. app/main.py +23 -3
app/index.html CHANGED
@@ -4,13 +4,41 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>saphir.ai</title>
7
- <link rel="stylesheet" type="text/css" href="/static/styles.css">
8
- </head>
9
- <body>
10
- <div class="container">
11
- <h1>saphir.ai</h1>
12
- <h2>Hugging Face Experiment</h2>
13
- <p>This is a simple HTML response from FastAPI.</p>
14
- </div>
15
- </body>
16
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>saphir.ai</title>
7
+ <link rel="stylesheet" type="text/css" href="/static/styles.css">
8
+ </head>
9
+ <body>
10
+ <div class="container">
11
+ <h1>saphir.ai</h1>
12
+ <h2>Hugging Face Experiment</h2>
13
+ <p>This is a simple HTML response from FastAPI.</p>
14
+ </div>
15
+
16
+ <div class="container">
17
+ <h3>Using the Swagger UI for the Chatbot</h3>
18
+ <ol>
19
+ <li>Go to the Swagger UI by visiting <a href="https://pytzen-saphir.hf.space/docs">this link</a>.</li>
20
+ <li>Scroll down to the <code>/chatbot</code> POST method section.</li>
21
+ <li>Click on the <code>Try it out</code> button.</li>
22
+ <li>In the <code>question</code> field, enter: <strong>"What is the capital of France?"</strong></li>
23
+ <li>In the <code>context</code> field, enter: <strong>"France is a country in Western Europe. It has several beautiful cities, including Paris, which is its capital. France is known for its wine, sophisticated cuisine, and landmarks like the Eiffel Tower."</strong></li>
24
+ <li>Click the <code>Execute</code> button to submit the request.</li>
25
+ <li>Scroll down to see the server response, where you will find the answer.</li>
26
+ </ol>
27
+ <p>Try it out with different questions and contexts to see how the chatbot responds!</p>
28
+ </div>
29
+
30
+ <div class="container">
31
+ <h3>About the Chatbot Model</h3>
32
+ <p>The chatbot is powered by the <strong>'distilbert-base-cased-distilled-squad'</strong> model from Hugging Face's Transformers library. This model is a distilled version of BERT, optimized for question-answering tasks. It has been trained on the SQuAD dataset (Stanford Question Answering Dataset), which consists of questions posed by crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text from the corresponding reading passage.</p>
33
+ <p>What sets this model apart is its ability to provide context-based answers. For the model to accurately answer a question, it requires a context — a paragraph or text where the answer is likely to be found. The model uses this context to understand the question and extract the relevant answer. Without sufficient context, the model may not provide accurate or relevant answers.</p>
34
+ <p>Therefore, when using the chatbot, it's important to provide a well-defined question along with a comprehensive context that contains the information needed to answer the question. The example of finding the capital of France illustrates this: the context provided gives the model enough information to identify 'Paris' as the correct answer.</p>
35
+ </div>
36
+
37
+ <div class="container">
38
+ <h3>FastAPI ReDoc Documentation</h3>
39
+ <p>For an alternative documentation format, you can view the ReDoc documentation of the chatbot API. ReDoc provides a more visual and organized layout of the API endpoints and their descriptions. This can be especially helpful for understanding the structure and capabilities of the API in a more user-friendly format.</p>
40
+ <p>Access the ReDoc documentation by clicking <a href="https://pytzen-saphir.hf.space/redoc">here</a>.</p>
41
+ </div>
42
+
43
+ </body>
44
+ </html>
app/main.py CHANGED
@@ -1,19 +1,39 @@
1
- from fastapi import FastAPI
2
  from fastapi.responses import HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from transformers import pipeline
5
 
6
- app = FastAPI()
 
7
  app.mount('/static', StaticFiles(directory='app/static'), name='static')
 
 
8
  question_answerer = pipeline(task='question-answering',
9
  model='distilbert-base-cased-distilled-squad')
10
 
11
  @app.get('/', response_class=HTMLResponse)
12
  def read_root():
 
 
 
 
13
  with open('app/index.html', 'r') as html_file:
14
  return html_file.read()
15
 
16
  @app.post('/chatbot')
17
  async def ask_question(question: str, context: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  result = question_answerer(question=question, context=context)
19
- return {'answer': result['answer']}
 
1
+ from fastapi import FastAPI, Request
2
  from fastapi.responses import HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from transformers import pipeline
5
 
6
+ # Set the title of your FastAPI application
7
+ app = FastAPI(title="Saphir AI Chatbot")
8
  app.mount('/static', StaticFiles(directory='app/static'), name='static')
9
+
10
+ # Initialize your model
11
  question_answerer = pipeline(task='question-answering',
12
  model='distilbert-base-cased-distilled-squad')
13
 
14
  @app.get('/', response_class=HTMLResponse)
15
  def read_root():
16
+ """
17
+ Root Endpoint
18
+ Returns the main HTML page for the chatbot interface.
19
+ """
20
  with open('app/index.html', 'r') as html_file:
21
  return html_file.read()
22
 
23
  @app.post('/chatbot')
24
  async def ask_question(question: str, context: str):
25
+ """
26
+ Chatbot Endpoint
27
+ Takes a question and context, returns the answer from the chatbot.
28
+
29
+ Parameters:
30
+ - question: A string containing the question to be answered.
31
+ - context: A string containing the context in which the question
32
+ should be answered.
33
+
34
+ Returns:
35
+ A JSON object with the 'answer' field containing the response from
36
+ the chatbot.
37
+ """
38
  result = question_answerer(question=question, context=context)
39
+ return {'answer': result['answer']}