prathyush27 commited on
Commit
47c73ba
1 Parent(s): 33f5793

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ from langchain_community.llms import HuggingFaceHub
5
+ from langchain_community.llms import HuggingFaceTextGenInference
6
+
7
+ # Load your Telugu model
8
+ """ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
+ model_name = "Telugu-LLM-Labs/Telugu-Llama2-7B-v0-Instruct"
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16).to(device) """
12
+
13
+
14
+ ENDPOINT_URL = "https://api-inference.huggingface.co/models/Telugu-LLM-Labs/Telugu-Llama2-7B-v0-Instruct"
15
+ HF_TOKEN = ""
16
+
17
+ llm = HuggingFaceTextGenInference(
18
+ inference_server_url=ENDPOINT_URL,
19
+ max_new_tokens=512,
20
+ top_k=50,
21
+ temperature=0.1,
22
+ repetition_penalty=1.03,
23
+ server_kwargs={
24
+ "headers": {
25
+ "Authorization": f"Bearer {HF_TOKEN}",
26
+ "Content-Type": "application/json",
27
+ }
28
+ },
29
+ )
30
+
31
+ def summarize(text, llm):
32
+ instruction = "కింది వచనాన్ని సంగ్రహించండి: "
33
+ prompt = instruction + text
34
+ response = llm(prompt)
35
+ return response
36
+
37
+ input_text = "గూగుల్ వార్తలు అనేది గూగుల్ ద్వారా అభివృద్ధి చేయబడిన వార్తా అగ్రిగేటర్ సేవ..."
38
+ result = summarize(input_text, llm)
39
+ print(result)