Spaces:
Running
Running
rjavedv
commited on
Commit
·
b1e5b99
1
Parent(s):
35aa8a1
further updates
Browse files- .gitignore +1 -0
- app.py +120 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/test.py
|
app.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
30-01-2025
|
3 |
+
Rashid Javed
|
4 |
+
A simple dictionary to get word meaning, synonyms, antonyms
|
5 |
+
"""
|
6 |
+
from huggingface_hub import InferenceClient
|
7 |
+
import os
|
8 |
+
import requests as re
|
9 |
+
import json
|
10 |
+
import streamlit as st
|
11 |
+
|
12 |
+
##### start Def part
|
13 |
+
## Call selected LLM, get word def and return
|
14 |
+
def call_llm(lmodel: str, lword: str) -> str:
|
15 |
+
ltoken = os.getenv('HF_TOKEN')
|
16 |
+
sysmsg = 'You are an English language expert. you are precise in your output. Users will ask you a word and in your response you will include the word meaning, synonyms, antonyms, and word usage examples. Format your output in different sections to make it easy to read'
|
17 |
+
usermsg = lword
|
18 |
+
messages = [
|
19 |
+
{ "role": "system", "content": sysmsg },
|
20 |
+
{ "role": "user", "content": usermsg }
|
21 |
+
]
|
22 |
+
client = InferenceClient(
|
23 |
+
model= lmodel,
|
24 |
+
token= ltoken
|
25 |
+
)
|
26 |
+
|
27 |
+
completion = client.chat.completions.create(
|
28 |
+
model= lmodel,
|
29 |
+
messages= messages,
|
30 |
+
temperature=0.5,
|
31 |
+
max_tokens=2048,
|
32 |
+
top_p=0.7,
|
33 |
+
stream=False
|
34 |
+
)
|
35 |
+
return(completion.choices[0].message.content)
|
36 |
+
|
37 |
+
## Call Dictionary API and get word def
|
38 |
+
def call_dict_api(lword: str) -> str:
|
39 |
+
return 'helo'
|
40 |
+
|
41 |
+
##### end Def part
|
42 |
+
|
43 |
+
lmodel = 'meta-llama/Llama-3.2-3B-Instruct'
|
44 |
+
|
45 |
+
st.title('A simple dictionary')
|
46 |
+
lword = st.text_input(label='Enter word')
|
47 |
+
lmodel = st.selectbox('Choose Language Model:',
|
48 |
+
index=0,
|
49 |
+
options=['meta-llama/Llama-3.2-3B-Instruct', 'Qwen/Qwen2.5-1.5B-Instruct', 'microsoft/Phi-3.5-mini-instruct']
|
50 |
+
)
|
51 |
+
chk1 = st.checkbox(label='Use Language model to get word definition', value=True)
|
52 |
+
chk2 = st.checkbox(label='Use Dictionary API call to get word definition', value=True)
|
53 |
+
|
54 |
+
btn_submit = st.button(label='Submit')
|
55 |
+
st.write(os.environ)
|
56 |
+
col1, col2 = st.columns(2, border=True)
|
57 |
+
## when setting hf token in terminal remember to set witout ''
|
58 |
+
ltoken = os.getenv('HF_TOKEN')
|
59 |
+
print(ltoken)
|
60 |
+
#st.write(ltoken)
|
61 |
+
|
62 |
+
#lmodel = 'cardiffnlp/twitter-roberta-base-sentiment-latest' #Text classification
|
63 |
+
# lmodel = 'meta-llama/Llama-3.2-3B-Instruct' #Text Generation
|
64 |
+
# lmodel = 'microsoft/phi-4' #Not Working for inference API, model too large
|
65 |
+
# lmodel = 'PowerInfer/SmallThinker-3B-Preview' #Time out for this shit
|
66 |
+
lmodel = 'Qwen/Qwen2.5-1.5B-Instruct' #Working But output is in a strange format
|
67 |
+
# lmodel = 'mistralai/Mistral-Small-24B-Instruct-2501' #Not Working
|
68 |
+
# lmodel = 'microsoft/Phi-3.5-mini-instruct' #working
|
69 |
+
|
70 |
+
# client = InferenceClient(
|
71 |
+
# model= lmodel,
|
72 |
+
# token= ltoken
|
73 |
+
# )
|
74 |
+
|
75 |
+
# #loutput = client.text_classification("Today is a great day")
|
76 |
+
# #print('output=',loutput)
|
77 |
+
|
78 |
+
|
79 |
+
# completion = client.chat.completions.create(
|
80 |
+
# model= lmodel,
|
81 |
+
# messages= messages,
|
82 |
+
# temperature=0.5,
|
83 |
+
# max_tokens=2048,
|
84 |
+
# top_p=0.7
|
85 |
+
# #stream=False
|
86 |
+
# )
|
87 |
+
|
88 |
+
# print('Chat output : ')
|
89 |
+
# print(completion.choices[0].message.content)
|
90 |
+
sample_out = '''
|
91 |
+
Tolerate
|
92 |
+
Definition: To accept or allow something that one does not like or approve of, especially in a mild or passive way.
|
93 |
+
Synonyms: Accept, endure, put up with, overlook, tolerate
|
94 |
+
Antonyms: Disapprove, reject, condemn, despise
|
95 |
+
Usage examples:
|
96 |
+
1. The new law was difficult to tolerate.
|
97 |
+
2. I have to tolerate my boss's constant interruptions.
|
98 |
+
3. He was tolerant of her eccentricities.
|
99 |
+
4. We had to tolerate the long wait at the airport.
|
100 |
+
5. She tolerated his frequent late arrivals.
|
101 |
+
6. We have to tolerate the noise from the construction site.
|
102 |
+
7. He tolerated the criticism as a necessary part of his job.
|
103 |
+
8. She tolerated the small talk at the meeting.
|
104 |
+
9. We have to tolerate the inconvenience of the traffic.
|
105 |
+
10. He tolerated the long hours at work.
|
106 |
+
|
107 |
+
In these examples, "tolerate" is used to describe the acceptance or allowance of something that is not liked or approved of, often in a mild or passive manner.
|
108 |
+
'''
|
109 |
+
#### Dict API call
|
110 |
+
# dict_url = 'https://api.dictionaryapi.dev/api/v2/entries/en/'
|
111 |
+
# lword = 'Tolerate'
|
112 |
+
# api_url = dict_url + lword
|
113 |
+
# print(api_url)
|
114 |
+
# response = re.get(url=api_url)
|
115 |
+
# print(response.status_code)
|
116 |
+
# rjson = response.json()
|
117 |
+
# print(rjson)
|
118 |
+
# st.write(rjson)
|
119 |
+
|
120 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
requests
|