Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import (
|
| 3 |
DDIMScheduler,
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
from langchain.llms import HuggingFaceTextGenInference
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
from langchain.prompts import PromptTemplate
|
| 6 |
+
|
| 7 |
+
# Initialize the Qwen client
|
| 8 |
+
qwen_client = Client("Qwen/Qwen2-0.5B")
|
| 9 |
+
|
| 10 |
+
# Create a custom LLM class to use with LangChain
|
| 11 |
+
class QwenLLM(HuggingFaceTextGenInference):
|
| 12 |
+
def _call(self, prompt, stop=None):
|
| 13 |
+
result = qwen_client.predict(
|
| 14 |
+
query=prompt,
|
| 15 |
+
history=[],
|
| 16 |
+
system="You are a helpful assistant.",
|
| 17 |
+
api_name="/model_chat"
|
| 18 |
+
)
|
| 19 |
+
return result[0][1] # Extract the assistant's response
|
| 20 |
+
|
| 21 |
+
# Initialize the LLM
|
| 22 |
+
llm = QwenLLM(
|
| 23 |
+
inference_server_url="https://your-inference-server-url", # This is a placeholder
|
| 24 |
+
max_new_tokens=512,
|
| 25 |
+
top_k=10,
|
| 26 |
+
top_p=0.95,
|
| 27 |
+
typical_p=0.95,
|
| 28 |
+
temperature=0.1,
|
| 29 |
+
repetition_penalty=1.03
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Create the LCel chain
|
| 33 |
+
template = """You are a helpful AI assistant. Please respond to the following user input:
|
| 34 |
+
|
| 35 |
+
User: {user_input}"""
|
| 36 |
+
|
| 37 |
import torch
|
| 38 |
from diffusers import (
|
| 39 |
DDIMScheduler,
|