Browse Source

Make gradio and langchain optional dependencies (#676)

Matthias Reso 6 months ago
parent
commit
98707b72fd

+ 1 - 0
.github/scripts/spellcheck_conf/wordlist.txt

@@ -1451,3 +1451,4 @@ openhathi
 sarvam
 subtask
 acc
+langchain

+ 4 - 0
README.md

@@ -94,6 +94,10 @@ To use the sensitive topics safety checker install with:
 ```
 pip install llama-recipes[auditnlg]
 ```
+Some recipes require the presence of langchain. To install the packages follow the recipe description or install with:
+```
+pip install llama-recipes[langchain]
+```
 Optional dependencies can also be combines with [option1,option2].
 
 #### Install from source

+ 1 - 0
pyproject.toml

@@ -24,6 +24,7 @@ dynamic = ["dependencies"]
 vllm = ["vllm"]
 tests = ["pytest-mock"]
 auditnlg = ["auditnlg"]
+langchain = ["langchain_openai", "langchain", "langchain_community"]
 
 [project.urls]
 "Homepage" = "https://github.com/facebookresearch/llama-recipes/"

+ 5 - 1
recipes/quickstart/inference/local_inference/inference.py

@@ -6,7 +6,6 @@ import sys
 import time
 
 import fire
-import gradio as gr
 
 import torch
 
@@ -146,6 +145,11 @@ def main(
         user_prompt = "\n".join(sys.stdin.readlines())
         inference(user_prompt, temperature, top_p, top_k, max_new_tokens)
     else:
+        try:
+            import gradio as gr
+        except ImportError:
+            raise ImportError("This part of the recipe requires gradio. Please run `pip install gradio`")
+            
         gr.Interface(
             fn=inference,
             inputs=[

+ 0 - 4
requirements.txt

@@ -14,7 +14,6 @@ py7zr
 scipy
 optimum
 matplotlib
-gradio
 chardet
 openai
 typing-extensions==4.8.0
@@ -24,8 +23,5 @@ rouge_score
 pyyaml==6.0.1
 faiss-gpu; python_version < '3.11'
 unstructured[pdf]
-langchain_openai
-langchain
-langchain_community
 sentence_transformers
 codeshield