GamerBhai02

Workshop

Sep 23rd, 2025
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.96 KB | Source Code | 0 0
  1. ollama_demo.py
  2. from langchain_ollama import ChatOllama
  3. import streamlit as st
  4. from langchain import PromptTemplate
  5.  
  6. ai = ChatOllama(model="llama3:8b")
  7. prompt_template = PromptTemplate(
  8.     input_variables={"country"},
  9.     template='''
  10.    You are an expert in traditional cuisines.
  11.    you must provide information about a specific dish from a specific country.
  12.    Answer the question: What is the traditional cuisine of the {country}?
  13.    '''
  14. )
  15. st.title("Get Cuisine Information")
  16. country = st.text_input("Enter a country:")
  17.  
  18. if country:
  19.     response = ai.invoke(prompt_template.format(country=country))
  20.     st.write(response.content)
  21.  
  22.  
  23.  
  24. prompt_template_demo.py
  25. from langchain_ollama import ChatOllama
  26. import streamlit as st
  27. from langchain_core.prompts import PromptTemplate
  28. from langchain.globals import set_debug
  29. set_debug(True)
  30.  
  31. ai = ChatOllama(model="llama3:8b")
  32. prompt_template = PromptTemplate(
  33.     input_variables={"country", "no_of_paras", "language"},
  34.     template='''
  35.    You are a world-renowned culinary expert specializing in traditional cuisines from around the globe.
  36.    Your task is to describe the traditional cuisine of {country} in exactly {no_of_paras} paragraph(s).
  37.  
  38.    Each paragraph should be informative, culturally rich, and reflect authentic culinary practices or dishes from the region.
  39.  
  40.    Important constraints:
  41.    - Write only in {language}.
  42.    - Do not exceed or fall short of {no_of_paras} paragraph(s).
  43.    - Focus on one or more iconic dishes, ingredients, cooking methods, or cultural significance.
  44.  
  45.    Begin your response now.
  46.    '''
  47. )
  48. st.title("Get Cuisine Information")
  49. country = st.text_input("Enter a country:")
  50. no_of_paras = st.text_input("Enter number of paras:")
  51. language = st.text_input("Enter a language:")
  52.  
  53. if country:
  54.     response = ai.invoke(prompt_template.format(country=country, no_of_paras=no_of_paras, language=language))
  55.     st.write(response.content)
  56.  
  57.  
  58. single_chain.py
  59. from langchain_ollama import ChatOllama
  60. import streamlit as st
  61. from langchain_core.prompts import PromptTemplate
  62. from langchain.globals import set_debug
  63. set_debug(True)
  64.  
  65. ai = ChatOllama(model="llama3:8b")
  66. prompt_template = PromptTemplate(
  67.     input_variables={'country','month','budget'},
  68.     template='''
  69.    You are an expert travel guide.
  70.    Now you must provide information about the place to visit in {country} during {month} with {budget} budget and the best local cuisine to try out.
  71.    Make sure the place is must-visit attraction and good to visit during the month with specific budget and best local cuisine.
  72.    Now give your response.
  73.    '''
  74. )
  75.  
  76. st.title("Travel Guide")
  77. country = st.text_input("Enter country name:")
  78. month = st.text_input("Enter month:")
  79. budget = st.selectbox(
  80.     "What is your budget?",
  81.     ("Low", "Medium", "High"),
  82. )
  83.  
  84. if country and month and budget:
  85.     response = ai.invoke(prompt_template.format(country=country, month=month, budget=budget))
  86.     st.write(response.content)
  87.  
  88.  
  89.  
  90. speech_generator.py
  91. from langchain_ollama import ChatOllama
  92. import streamlit as st
  93. from langchain_core.prompts import PromptTemplate
  94. from langchain.globals import set_debug
  95. set_debug(True)
  96.  
  97. ai = ChatOllama(model="llama3:8b")
  98. title_template = PromptTemplate(
  99.     input_variables={'topic'},
  100.     template='''
  101.    you are an experienced speech writer.
  102.    you need to craft an impactful title for a speech on the following topic: {topic}
  103.    answer exactly with one title
  104.    '''
  105. )
  106. speech_template = PromptTemplate(
  107.     input_variables={'title'},
  108.     template='''
  109.    you need to craft an powerful speech of 350 words for the following topic: {topic}
  110.    '''
  111. )
  112.  
  113. st.title("Speech Generator")
  114. topic = st.text_input("Enter topic:")
  115.  
  116. first_chain = title_template | ai
  117. second_chain = speech_template | ai
  118. final_chain = first_chain | second_chain
  119.  
  120. if topic:
  121.     response = final_chain.invoke({'topic':topic})
  122.     st.write(response.content)
  123.  
  124.  
  125.  
  126. travel_guide.py
  127. from langchain_ollama import ChatOllama
  128. import streamlit as st
  129. from langchain_core.prompts import PromptTemplate
  130. from langchain.globals import set_debug
  131. set_debug(True)
  132.  
  133. ai = ChatOllama(model="llama3:8b")
  134. prompt_template = PromptTemplate(
  135.     input_variables={'country','month','budget'},
  136.     template='''
  137.    You are an expert travel guide.
  138.    Now you must provide information about the place to visit in {country} during {month} with {budget} budget and the best local cuisine to try out.
  139.    Make sure the place is must-visit attraction and good to visit during the month with specific budget and best local cuisine.
  140.    Now give your response.
  141.    '''
  142. )
  143.  
  144. st.title("Travel Guide")
  145. country = st.text_input("Enter country name:")
  146. month = st.text_input("Enter month:")
  147. budget = st.selectbox(
  148.     "What is your budget?",
  149.     ("Low", "Medium", "High"),
  150. )
  151.  
  152. chain = prompt_template | ai
  153. if country and month and budget:
  154.     response = chain.invoke({'country':country, 'month':month, 'budget':budget})
  155.     st.write(response.content)
Tags: workshop
Advertisement
Add Comment
Please, Sign In to add comment