Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from langserve import add_routes
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
@@ -50,7 +49,7 @@ generator = pipeline(
|
|
| 50 |
# LangChain pipeline
|
| 51 |
llm = HuggingFacePipeline(pipeline=generator)
|
| 52 |
prompt = ChatPromptTemplate.from_template(
|
| 53 |
-
|
| 54 |
Explain this Python code step-by-step:
|
| 55 |
Use code with caution
|
| 56 |
{code}
|
|
@@ -64,3 +63,7 @@ chain = prompt | llm | parser
|
|
| 64 |
# Add route
|
| 65 |
add_routes(app, chain, path="/explain")
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from langserve import add_routes
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
|
| 49 |
# LangChain pipeline
|
| 50 |
llm = HuggingFacePipeline(pipeline=generator)
|
| 51 |
prompt = ChatPromptTemplate.from_template(
|
| 52 |
+
"""Instruction:
|
| 53 |
Explain this Python code step-by-step:
|
| 54 |
Use code with caution
|
| 55 |
{code}
|
|
|
|
| 63 |
# Add route
|
| 64 |
add_routes(app, chain, path="/explain")
|
| 65 |
|
| 66 |
+
# Run server (necessary for Hugging Face Spaces)
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
import uvicorn
|
| 69 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|