Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
from ollama import AsyncClient
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
async def chat(prompt):
|
6 |
+
message = {'role': 'user', 'content': prompt}
|
7 |
+
async for part in await AsyncClient().chat(model='smollm:135m', messages=[message], stream=True):
|
8 |
+
yield part['message']['content']
|
9 |
+
|
10 |
+
async def get_full_response(prompt):
|
11 |
+
response = ""
|
12 |
+
async for part in chat(prompt):
|
13 |
+
response += part
|
14 |
+
return response
|
15 |
+
|
16 |
+
def main():
|
17 |
+
st.title("MySQL with Llama-3")
|
18 |
+
prompt = st.text_input("Enter your prompt:")
|
19 |
+
|
20 |
+
if st.button("Generate"):
|
21 |
+
if prompt:
|
22 |
+
with st.spinner("Generating response..."):
|
23 |
+
full_response = asyncio.run(get_full_response(prompt))
|
24 |
+
st.write(full_response)
|
25 |
+
|
26 |
+
if __name__ == '__main__':
|
27 |
+
main()
|