Spaces:
Sleeping
Sleeping
test
Browse files
libs/transformer/get_chat_transformer.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn import pipeline
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def get_chat_transformers(messages: list):
|
| 6 |
+
model = AutoModelForImageTextToText.from_pretrained("Xkev/Llama-3.2V-11B-cot")
|
| 7 |
+
|
| 8 |
+
pipe = pipeline("text-generation",
|
| 9 |
+
model=model,
|
| 10 |
+
|
| 11 |
+
device_map="auto",)
|
| 12 |
+
|
| 13 |
+
pipe = pipeline("text-generation", model="meta-llama/Llama-3.1-8B-Instruct")
|
| 14 |
+
|
| 15 |
+
outputs = pipe(messages)
|
| 16 |
+
|
| 17 |
+
return outputs[0]["generated_text"][-1]
|
routers/get_chatrespone.py
CHANGED
|
@@ -12,6 +12,7 @@ from fastapi.responses import StreamingResponse
|
|
| 12 |
from langchain_ollama import ChatOllama, OllamaLLM
|
| 13 |
|
| 14 |
from libs.transformer.get_chat_gradio import get_chat_gradio
|
|
|
|
| 15 |
|
| 16 |
load_dotenv()
|
| 17 |
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN", )
|
|
@@ -42,9 +43,18 @@ async def get_chat_respone(body: ChatInputForm, api_key: str = Depends(get_api_k
|
|
| 42 |
# ("human", body.textInput)
|
| 43 |
# ]
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# response = llm.stream(messages)
|
| 46 |
|
| 47 |
-
response = get_chat_gradio(body.textInput)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
return StreamingResponse(get_response(response), media_type='text/event-stream')
|
| 50 |
except Exception:
|
|
|
|
| 12 |
from langchain_ollama import ChatOllama, OllamaLLM
|
| 13 |
|
| 14 |
from libs.transformer.get_chat_gradio import get_chat_gradio
|
| 15 |
+
from libs.transformer.get_chat_transformer import get_chat_transformers
|
| 16 |
|
| 17 |
load_dotenv()
|
| 18 |
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN", )
|
|
|
|
| 43 |
# ("human", body.textInput)
|
| 44 |
# ]
|
| 45 |
|
| 46 |
+
messages = [
|
| 47 |
+
{"role": "system", "content": prompt},
|
| 48 |
+
{"role": "user", "content": body.textInput},
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
# response = llm.stream(messages)
|
| 52 |
|
| 53 |
+
# response = get_chat_gradio(body.textInput)
|
| 54 |
+
|
| 55 |
+
response = get_chat_transformers(messages)
|
| 56 |
+
|
| 57 |
+
print(response)
|
| 58 |
|
| 59 |
return StreamingResponse(get_response(response), media_type='text/event-stream')
|
| 60 |
except Exception:
|
routers/get_transcript_transformer.py
CHANGED
|
@@ -30,7 +30,7 @@ def get_transcript(audio_path: str, model_size: str = "distil-whisper/distil-sma
|
|
| 30 |
convert_to_audio(audio_path.strip(), output_file)
|
| 31 |
|
| 32 |
try:
|
| 33 |
-
text, chunks = get_transcribe_transformers(output_file,
|
| 34 |
except Exception as error:
|
| 35 |
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"error>>>: {error}")
|
| 36 |
finally:
|
|
|
|
| 30 |
convert_to_audio(audio_path.strip(), output_file)
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
text, chunks = get_transcribe_transformers(output_file, "Xkev/Llama-3.2V-11B-cot")
|
| 34 |
except Exception as error:
|
| 35 |
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"error>>>: {error}")
|
| 36 |
finally:
|