Spaces:
Runtime error
Runtime error
Commit
·
97a631f
1
Parent(s):
32a1cc1
Upload 4 files
Browse files- DockerFile +14 -0
- main.py +32 -0
- requirements.txt +6 -0
- templates/index.html +123 -0
DockerFile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
WORKDIR /code
|
| 7 |
+
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860" "main:app", "--host"]
|
main.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request
|
| 2 |
+
from langchain.llms import OpenAI
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Function to load OpenAI model and get responses
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_openai_response(question):
|
| 10 |
+
llm = OpenAI(
|
| 11 |
+
openai_api_key=app.config['OPENAI_API_KEY'],
|
| 12 |
+
model_name="text-davinci-003",
|
| 13 |
+
temperature=0.5
|
| 14 |
+
)
|
| 15 |
+
response = llm(question)
|
| 16 |
+
return response
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@app.route('/', methods=['GET', 'POST'])
|
| 20 |
+
def index():
|
| 21 |
+
if request.method == 'POST':
|
| 22 |
+
input_question = request.form['input']
|
| 23 |
+
response = get_openai_response(input_question)
|
| 24 |
+
return render_template('index.html', input_question=input_question, response=response)
|
| 25 |
+
|
| 26 |
+
return render_template('index.html')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
if __name__ == '__main__':
|
| 30 |
+
# Replace with your OpenAI API key
|
| 31 |
+
app.config['OPENAI_API_KEY'] = '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'
|
| 32 |
+
app.run(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
openai
|
| 3 |
+
huggingface_hub
|
| 4 |
+
python-dotenv
|
| 5 |
+
gunicorn
|
| 6 |
+
flask
|
templates/index.html
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
| 8 |
+
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
| 9 |
+
<title>Q&A Demo</title>
|
| 10 |
+
<style>
|
| 11 |
+
#input:focus,
|
| 12 |
+
#input:active,
|
| 13 |
+
#input:hover {
|
| 14 |
+
border-color: #c090fe !important;
|
| 15 |
+
outline: none;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
.body {
|
| 19 |
+
height: 100vh;
|
| 20 |
+
width: 100vw;
|
| 21 |
+
background-color: #212121;
|
| 22 |
+
display: flex;
|
| 23 |
+
flex-direction: column;
|
| 24 |
+
align-items: center;
|
| 25 |
+
justify-content: center;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.custom-form {
|
| 29 |
+
background-color: #212121;
|
| 30 |
+
width: 30%;
|
| 31 |
+
border: 2px solid #c090fe;
|
| 32 |
+
border-radius: 30px;
|
| 33 |
+
padding: 20px;
|
| 34 |
+
margin-top: 5%;
|
| 35 |
+
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.response {
|
| 39 |
+
overflow-y: auto;
|
| 40 |
+
max-height: 30vh;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.response::-webkit-scrollbar {
|
| 44 |
+
width: 0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.btn-grp {
|
| 48 |
+
display: flex;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.form-btn {
|
| 52 |
+
width: 100%;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
@media (max-width: 600px) {
|
| 56 |
+
.custom-form {
|
| 57 |
+
width: 80%;
|
| 58 |
+
/* Adjust the width for smaller screens */
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.btn-grp {
|
| 62 |
+
flex-direction: column;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
@media (min-width: 601px) and (max-width: 900px) {
|
| 67 |
+
.custom-form {
|
| 68 |
+
width: 70%;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
@media (min-width: 901px) and (max-width: 1200px) {
|
| 73 |
+
.custom-form {
|
| 74 |
+
width: 50%;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
@media (min-width: 1201px) {
|
| 79 |
+
.custom-form {
|
| 80 |
+
width: 30%;
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
</style>
|
| 84 |
+
|
| 85 |
+
</head>
|
| 86 |
+
|
| 87 |
+
<body class="body">
|
| 88 |
+
<h1 class="text-white" style="word-wrap: normal; text-align: center;">Langchain Application</h1>
|
| 89 |
+
<div class="text-white px-5 py-xl-5 mt-5 custom-form">
|
| 90 |
+
<form method="post" action="/">
|
| 91 |
+
<div class="form-group">
|
| 92 |
+
<label for="question" class="h4">What is your question?</label>
|
| 93 |
+
<input type="text" id="input" name="input" class="form-control" placeholder="Question"
|
| 94 |
+
style="background-color: #212121; color: white; border: 2px solid ;">
|
| 95 |
+
</div>
|
| 96 |
+
<div class="btn-grp">
|
| 97 |
+
<button type="submit" class="btn btn-primary form-btn">Submit</button>
|
| 98 |
+
<button type="reset" class="btn btn-secondary form-btn">Cancel</button>
|
| 99 |
+
</div>
|
| 100 |
+
</form>
|
| 101 |
+
|
| 102 |
+
{% if input_question %}
|
| 103 |
+
<p class="mt-4 h4">The Response is</p>
|
| 104 |
+
<div class="response">
|
| 105 |
+
<p>{{ response }}</p>
|
| 106 |
+
</div>
|
| 107 |
+
{% endif %}
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<!-- Optional JavaScript -->
|
| 111 |
+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
| 112 |
+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
|
| 113 |
+
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
|
| 114 |
+
crossorigin="anonymous"></script>
|
| 115 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
|
| 116 |
+
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
|
| 117 |
+
crossorigin="anonymous"></script>
|
| 118 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
|
| 119 |
+
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
| 120 |
+
crossorigin="anonymous"></script>
|
| 121 |
+
</body>
|
| 122 |
+
|
| 123 |
+
</html>
|